Package Chronos

Indexing

Package:Chronos
Author:Stefan Rusterholz
Contact:stefan@brightlight.ch
Version:0.9.2
Date:2005-02-23 [1109171542]
Tabulator:4 spaces

This document

This document is written in ISO-Latin-1 with Unix-Lineendings. Tabulator uses 4 spaces.
I don't like it if code is cramed with comments. In my oppinion the code itself should be as readable as possible (no short variable names, no abbreviated function names). But of course that doesn't make documentation obsolete, that's why this document exists.

Description

The package chronos consists of the classes datetime, difference, timespan, location and chronos which are intended to let you easily deal with everything related to time & date. It allows you to deal with:

What this library does not do for you:

*See NOTES, different behaviour is difficult

IMMINENT CHANGES

Be aware that this class is a pre 1.0 release and I probably will change some of the interfaces and functions What I'm still unhappy with is:

Norms & Links

Dates:

Times:

Locations:

Timezones:

Notes

Bugs

ToDo

class datetime

method datetime()

Synopsis

// timezone will be local timezone, language is 'en'
$now            = new datetime("current");
// another variant of the sample above
$now            = new datetime(time());
// language will be 'de' (default for Europe/Zurich)
$date           = new datetime("2005-12-31", "Europe/Zurich");
// you can create time-only objects as well
$time           = new datetime("13:45:21", "Europe/Zurich");
// this pattern will be recognized because german-strings are loaded
$datetime       = new datetime("31.12.2005 13:45", , "Europe/Zurich", "de");
// you can create from an array
$datetime       = new datetime(array('day' => 31, 'month' => 12, 'year' => 2005, 'hour' => 13, 'minute' => 45), "Europe/Zurich");

Return

VOID Creates a new Object

Arguments

ArgumentTypeDefaultDescription
$datetimeMIXED the datetime to create the new object from. Can be either an array with the keys ('day', 'month', 'year') or ('week','dayofweek','year') for date and/or ('hour','minute','second') for time.
For missing date-parts the default value is current-date (e.g. if you ommit year the current year will be taken).
For missing time-parts the default value is 0 (e.g. if you ommit the seconds it will be set to 0).
$timezoneIDSTRING Either one of the timezone-id's like America/Los_Angeles (see data.locations.tab) or use a utc-name 'UTC±difference' like 'UTC', 'UTC+1' or 'UTC-4'. Timezone-IDs are prefered since they can determine the whished language, DST-behaviour and geographic position as well.
$languageSTRING An ISO 3166 two-letter-countrycode (like 'en', 'de' or 'fr'). The language parameter will override the setting retrieved from a timezone-ID. This can be useful if you want to print a date from another country but in your language.

Description

Creates a new date/time object from $datetime using create_fromString (if $datetime is a string), create_fromUnixtime (if $datetime is an integer) or create_fromArray (if $datetime is an array).

method create_fromString()

Synopsis

$result	= $datetime->create_fromString('1/1/2005 13.45', false);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$stringSTRING A string containing a date and/or time in any format known in the loaded language files
$croakBOOL If $croak is true the function will trigger an error if it can not match the string or if the recognized date is corrupt.
Set this to false if you want to parse e.g. formular input where it is not sure that a date/time can be matched.

Description

Sets the date/time from a human- or machine-readable string. Useful for date/time fields in forms.

method create_fromUnixtime()

Synopsis

$result	= $datetime->create_fromUnixtime(1108500000);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$unixtimeINT The unixtimestamp from which you want to create a datetime-object.

Description

Set the date/time from a unixtimestamp.

method create_fromMySQL()

Synopsis

$result	= $datetime->create_fromMySQL('2005-01-20 12:00:00');
$result	= $datetime->create_fromMySQL('20050120120000'); // the same as above

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$integerSTRING A MySQL datetime stamp in either the integer-format (yyyymmddHHMMSS) or string-format ('yyyy-mm-dd HH:MM:SS').

Description

Set the date/time from a MYSQL-datetime or -timestamp field.

method create_fromCurrent()

Synopsis

$result	= $datetime->create_fromCurrent();

Return

BOOL Success

Description

Sets date and time to current date and time.

method create_fromArray()

Synopsis

// sets datetime to '2005-01-20 12:59:02'
$result         = create_fromArray(array('year' => 2005, 'month' => 1, 'day' => 20, 'hour' => 12, 'minute' => 59, 'second' => 2);
// sets datetime to 'current year-01-20 12:00:00'
$result         = create_fromArray(array('month' => 1, 'day' => 20, 'hour' => 12);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$arrayARRAY The components of date/time, can use the keys: year, month, day, hour, minute, second, timezone
If no date-part is supplied a time-object is created.
If no time-part is supplied a date-object is created.
If at least one date-part is supplied, the default for omitted date-parts is the current date (e.g. you ommit the year, then the current year will be taken)
If at least one time-part is supplied, the default for omitted time-parts is 0.

Description

Set time/date from an array containing the parts.
We make an educated guess what defaults to take. Idea is following:
-if a datepart is supplied we fill in gaps with current date (e.g. month and day are supplied we complement year with current year)
-if a timepart is supplied we fill in gaps with 0
-timezone: argument > creation-supplied > default (means: if given in the array, that value will be taken, else it falls back to the timezone given at creation or in worst case uses default)

method set_micro()

Synopsis

$result	= $datetime->set_micro(456);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$microINT Set the microseconds-part of a datetime-object to $micro

Description

Set the microseconds-part of the time
Date-Objects will automatically become datetime-object if this method is used.

method set_milli()

Synopsis

$result	= $datetime->set_milli(123);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$milliINT Set the milliseconds-part of a datetime-object to $milli

Description

Set the milliseconds-part of the time
Date-Objects will automatically become datetime-object if this method is used.

method set_second()

Synopsis

$result	= $datetime->set_second(52);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$secondINT Set the seconds-part of a datetime-object to $second

Description

Set the seconds-part of the time
Date-Objects will automatically become datetime-object if this method is used.

method set_minute()

Synopsis

$result	= $datetime->set_minute(45);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$minuteINT Set the minutes-part of a datetime-object to $minute

Description

Set the minutes-part of the time
Date-Objects will automatically become datetime-object if this method is used.

method set_hour()

Synopsis

$result	= $datetime->set_hour(13);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$hourINT Set the hours-part of a datetime-object to $hour

Description

Set the hours-part of the time
Date-Objects will automatically become datetime-object if this method is used.

method set_day()

Synopsis

$result	= $datetime->set_day(21);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$dayINT The day of the year to which the date should be set. It will become converted to the according month and day of month.
$monthINT The month of which the day is set. If set to false, get_month() is used.
You should NOT use this argument, it is only for internal purposes.
$yearINT The year of which the day is set. If set to false, get_year() is used.
You should NOT use this argument, it is only for internal purposes.

Description

Set the day of the month to $day.

method set_dayOfYear()

Synopsis

$result	= $datetime->set_dayOfYear(121);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$dayOfYearINT The day of the year to which the date should be set. It will become converted to the according month and day of month.
$yearINT The year of which the day-of-year is set. If set to false, get_year() is used.
You should NOT use this argument, it is only for internal purposes.

Description

Set the date (day-of-month and month) to a specific day of the year.

method set_month()

Synopsis

$result	= $datetime->set_month(1);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$monthINT The month to which the date should be set.

Description

Set the month to $month.

method set_year()

Synopsis

$result	= $datetime->set_year($year);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$yearINT The year to which the date should be set.

Description

Set the year to $year.

method setTo_nthDayOfWeek()

Synopsis

// set date to monday
$result	= $datetime->setTo_nthDayOfWeek(0);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$nINT Date set to {$n}th day of week, time is preserved
If $n is negative date is set to the {$n}th-last day of week

Description

Set the date to a specific weekday of the current week.

method setTo_nthDayOfMonth()

Synopsis

// set date to last day of the month
$result	= $datetime->setTo_nthDayOfMonth(-1);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$nINT Date set to {$n}th day of month, time is preserved
If $n is negative date is set to the {$n}th-last day of month

Description

Set the date to a specific day of month.

method setTo_nthDayOfYear()

Synopsis

// set date to last day of the year
$result	= $datetime->setTo_nthDayOfYear(-1);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$nINT Date set to {$n}th day of year, time is preserved
If $n is negative date is set to the {$n}th-last day of year

Description

Set the date to a specific day of the year.

method setTo_nthWeekOfYear()

Synopsis

// set the date to the same weekday as it is at the moment but in the first week of the year
$result	= $datetime->setTo_nthWeekOfYear(1, false);
// set the date to monday of the first week of the year
$result	= $datetime->setTo_nthWeekOfYear(1, 0);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$nINT Date set to {$n}th week of year, time is preserved
$weekdayINT Date set to weekday $weekday (false for preserving current weekday)

Description

Set the date to a specific weekday of a specific week of the year.

method setTo_sunrise()

Synopsis

// Set the time to the time of the sunrise
$result	= $datetime->setTo_sunrise();

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$locationMIXED False (default) for using current timezone-ID's coordinates
A location object
A coordinates-array in form: array([FLOAT]latitude, [FLOAT]longitude)
A string containing a valid timezoneID

Description

Changes time of datetime object to the time of sunrise in location $location

method setTo_sunset()

Synopsis

$result	= $datetime->setTo_sunset($location);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$locationMIXED False (default) for using current timezone-ID's coordinates
A location object
A coordinates-array in form: array([FLOAT]latitude, [FLOAT]longitude)
A string containing a valid timezoneID

Description

Changes time of datetime object to the time of sunset in location $location

method setTo_morningTwilight()

Synopsis

$result	= $datetime->setTo_morningTwilight($location);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$locationMIXED False (default) for using current timezone-ID's coordinates
A location object
A coordinates-array in form: array([FLOAT]latitude, [FLOAT]longitude)
A string containing a valid timezoneID

Description

Changes time of datetime object to the time of morning-twilight in location $location

method setTo_eveningTwilight()

Synopsis

$result	= $datetime->setTo_eveningTwilight($location);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$locationMIXED False (default) for using current timezone-ID's coordinates
A location object
A coordinates-array in form: array([FLOAT]latitude, [FLOAT]longitude)
A string containing a valid timezoneID

Description

Changes time of datetime object to the time of evening-twilight in location $location

method do_add()

Synopsis

$result	= $datetime->do_add($differenceOrArray);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$differenceOrArrayMIXED Difference-Object or array with one or more of the keys 'seconds', 'minutes', 'hours', 'days', 'weeks', 'months', 'years'

Description

Adds a datetime-difference (any combination of seconds, minutes, hours, days, weeks, months and years) to the datetime.

method do_addSeconds()

Synopsis

$result	= $datetime->do_addSeconds($seconds);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$secondsINT Amount of seconds to add

Description

Adds $seconds seconds to the datetime.

method do_addMinutes()

Synopsis

$result	= $datetime->do_addMinutes($minutes);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$minutesINT Amount of minutes to add

Description

Adds $seconds seconds to the datetime.

method do_addHours()

Synopsis

$result	= $datetime->do_addHours($hours);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$hoursINT Amount of seconds to add

Description

Adds $hours hours to the datetime.

method do_addDays()

Synopsis

$result	= $datetime->do_addDays($days);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$daysINT Amount of days to add

Description

Adds $days days to the datetime.

method do_addMonths()

Synopsis

$result	= $datetime->do_addMonths($months, $cutOverflow);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$monthsINT Amount of months to add
$cutOverflowBOOL If overflow days should be added or just cut

Description

Adds $monts monts to the datetime.
If cutOverflow is false, then 31.3. +1month is eqal 1.5. Else it is equal 30.4. (since there is no 31.4.).

method do_addYears()

Synopsis

$result	= $datetime->do_addYears($years);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$yearsINT Amount of years to add

Description

Adds $years years to the datetime.

method do_subtractDatetime()

Synopsis

$result	= $datetime->do_subtractDatetime($subtrahend);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$subtrahendOBJECT Datetime-Object to subtract from $this

Description

Subtracts a datetime from the datetime.
This operation changes the object-type to a difference-object.
You can use datetime->do_subtract() instead.

method do_subtract()

Synopsis

$result	= $datetime->do_subtract($differenceDatetimeOrArray);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$differenceDatetimeOrArrayMIXED Difference-, Datetime-Object or array with one or more of the keys 'seconds', 'minutes', 'hours', 'days', 'weeks', 'months', 'years'

Description

Subtracts a datetime or a datetime-difference (any combination of seconds, minutes, hours, days, weeks, months and years) from the datetime.
If you subtract a datetime the object-type will be changed to a difference-object.

method do_subtractSeconds()

Synopsis

$result	= $datetime->do_subtractSeconds($seconds);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$secondsINT Amount of seconds to subtract

Description

Subtracts $seconds seconds from the datetime.

method do_subtractMinutes()

Synopsis

$result	= $datetime->do_subtractMinutes($minutes);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$minutesINT Amount of minutes to subtract

Description

Subtracts $minutes minutes from the datetime.

method do_subtractHours()

Synopsis

$result	= $datetime->do_subtractHours($hours);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$hoursINT Amount of hours to subtract

Description

Subtracts $hours hours from the datetime.

method do_subtractDays()

Synopsis

$result	= $datetime->do_subtractDays($days);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$daysINT Amount of days to subtract

Description

Subtracts $days days from the datetime.

method do_subtractMonths()

Synopsis

$result	= $datetime->do_subtractMonths($months, $cutOverflow);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$yearsINT Amount of years to subtract
$cutOverflowBOOL If overflow days should be added or just cut

Description

Subtracts $years years from the datetime.
If cutOverflow is false, then 31.3. +1month is eqal 1.5. Else it is equal 30.4. (since there is no 31.4.).

method do_subtractYears()

Synopsis

$result	= $datetime->do_subtractYears($years);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$yearsINT Amount of years to subtract

Description

Subtracts $years years from the datetime.

method get_nthDayOfWeek()

Synopsis

$result	= $datetime->get_nthDayOfWeek($n);

Return

OBJECT The datetime-object set to the n. day of the week

Arguments

ArgumentTypeDefaultDescription
$nINT Date set to {$n}th day of week, time is preserved
If $n is negative date is set to the {$n}th-last day of week

Description

Return a new datetime object with the date set to a specific weekday of the current week.

method get_nthDayOfMonth()

Synopsis

$result	= $datetime->get_nthDayOfMonth($n);

Return

OBJECT The datetime-object set to the n. day of the month

Arguments

ArgumentTypeDefaultDescription
$nINT Date set to {$n}th day of month, time is preserved
If $n is negative date is set to the {$n}th-last day of month

Description

Return a new datetime object with the date set to a specific day of month.

method get_nthDayOfYear()

Synopsis

$result	= $datetime->get_nthDayOfYear($n);

Return

OBJECT The datetime-object set to the n. day of the year

Arguments

ArgumentTypeDefaultDescription
$nINT Date set to {$n}th day of year, time is preserved
If $n is negative date is set to the {$n}th-last day of year

Description

Return a new datetime object with the date set to a specific day of the year.

method get_nthWeekOfYear()

Synopsis

$result	= $datetime->get_nthWeekOfYear($n, $weekday);

Return

OBJECT The datetime-object set to a specific weekday of the n. week of the year

Arguments

ArgumentTypeDefaultDescription
$nINT Date set to {$n}th week of year, time is preserved
$weekdayINT Date set to weekday $weekday (false for preserving current weekday)

Description

Return a new datetime object with the date set to a specific weekday of a specific week of the year.

method get_dayOfWeek()

Synopsis

$result	= $datetime->get_dayOfWeek($format);

Return

MIXED Returns the day of week in a form depending on $format. Numeric values range from 0-6, where 0 represents the start of the week (monday).

Arguments

ArgumentTypeDefaultDescription
$formatSTRING Specifies in what format the day-of-week is returned. Valid are following values:
-'alldigits': will return a padded number corresponding to the day of the week
-'integer': will return the day of the week as integer
-'string': will look up the weekdays name in the active language file

Description

Return the weekday either as integer, padded-integer or localized string.

method get_dayOfMonth()

Synopsis

$result	= $datetime->get_dayOfMonth($format);

Return

MIXED Returns the day of month in a form depending on $format. Numeric values range from 1-31.

Arguments

ArgumentTypeDefaultDescription
$formatSTRING Specifies in what format the day-of-month is returned. Valid are following values:
-'alldigits': will return a padded number corresponding to the day of the month
-'integer': will return the day of the month as integer

Description

Return the day of month either as integer or as padded-integer.

method get_dayOfYear()

Synopsis

$result	= $datetime->get_dayOfYear($format);

Return

MIXED Returns the day of year in a form depending on $format. Numeric values range from 1-366.

Arguments

ArgumentTypeDefaultDescription
$formatSTRING Specifies in what format the day-of-year is returned. Valid are following values:
-'alldigits': will return a padded number corresponding to the day of the year
-'integer': will return the day of the year as integer

Description

Return the day of month either as integer or as padded-integer.

method get_daysOfMonth()

Synopsis

$result	= $datetime->get_daysOfMonth($month, $year);

Return

INT Amount of days of month $month of year $year.

Arguments

ArgumentTypeDefaultDescription
$monthINT Month of which you want to know the amount of days. Uses $this->get_month() if set to false.
$yearINT Year in which the month is (only important for february). Uses $this->get_year() if set to false.

Description

Returns the amount of days of month $month of year $year.

method get_weeksOfYear()

Synopsis

$result	= $datetime->get_weeksOfYear($year);

Return

INT Amount of weeks (52-53) year $year has.

Arguments

ArgumentTypeDefaultDescription
$yearINT Year of which to return amount of weeks. Uses $this->get_year() if set to false.

Description

Returns the amount of weeks year $year has.

method get_monthFromYearday()

Synopsis

$result	= $datetime->get_monthFromYearday($day, $year);

Return

INT The month (1-12) in which the day-of-year $day is.

Arguments

ArgumentTypeDefaultDescription
$dayINT Day of year from which you want to know in which month it is.
$yearINT Year in which the month is. Uses $this->get_year() if set to false.

Description

Returns the month (1-12) in which the day-of-year $day is.

method get_monthDayFromYearday()

Synopsis

$result	= $datetime->get_monthDayFromYearday($day, $year);

Return

INT Day of month (1-31) which the day of year corresponds to.

Arguments

ArgumentTypeDefaultDescription
$dayINT Day of year (1-365, 366 in leapyears).
$yearINT Year in which the month is (only important for february). Uses $this->get_year() if set to false.

Description

Returns the day of month (1-31) which the day of year corresponds to.

method get_date()

Synopsis

$result	= $datetime->get_date();

Return

ARRAY Dump of the date-part of the object

Description

Returns a dump of the date-part of the object.

method get_time()

Synopsis

$result	= $datetime->get_time();

Return

ARRAY Dump of the time-part of the object

Description

Returns a dump of the date-part of the object

method get_datetime()

Synopsis

$result	= $datetime->get_datetime();

Return

ARRAY Dump of the date & time-part of the object

Description

Returns a dump of the date & time-part of the object

method get_year()

Synopsis

$result	= $datetime->get_year($digits, $asInt);

Return

STRING Year of datetime

Arguments

ArgumentTypeDefaultDescription
$digitsINT How many digits of the year to return (2 and 4 are common)
$asIntBOOL Return the year as integer rather then as string

Description

Returns the year of datetime.

method get_month()

Synopsis

$result	= $datetime->get_month($format);

Return

MIXED The month in a form depending on $format. Numeric values range from 1-12.

Arguments

ArgumentTypeDefaultDescription
$formatSTRING Specifies in what format the month is returned. Valid are following values:
-'alldigits': will return a padded number corresponding to the month
-'integer': will return the month as integer
-'string': will look up the months name in the active language file

Description

Return the month either as integer, padded-integer or localized string. Numeric values range from 1-12.

method get_day()

Synopsis

$result	= $datetime->get_day($format);

Return

MIXED Returns the day of month in a form depending on $format. Numeric values range from 1-31.

Arguments

ArgumentTypeDefaultDescription
$formatSTRING Specifies in what format the day-of-month is returned. Valid are following values:
-'alldigits': will return a padded number corresponding to the day of the month
-'integer': will return the day of the month as integer

Description

Return the day of month either as integer or as padded-integer.

method get_hour()

Synopsis

$result	= $datetime->get_hour($format, $mode);

Return

MIXED Hour either as integer or padded-integer. Numeric values range from 1-12 or 1-24 (see $mode).

Arguments

ArgumentTypeDefaultDescription
$formatSTRING Specifies in what format the hour is returned. Valid are following values:
-'alldigits': will return a padded number corresponding to the hour
-'integer': will return the hour as integer
$modeINT Valid values are 12 and 24. Defines if the hour is returned as value 1-12 or as value 1-24.

Description

Returns the hour either as integer or padded-integer. Numeric values range from 1-12 or 1-24 (see $mode).

method get_minute()

Synopsis

$result	= $datetime->get_minute($format);

Return

MIXED Returns the minute in a form depending on $format. Numeric values range from 0-59.

Arguments

ArgumentTypeDefaultDescription
$formatSTRING Specifies in what format the minute is returned. Valid are following values:
-'alldigits': will return a padded number corresponding to the minute
-'integer': will return the minute as integer

Description

Return the minute either as integer or as padded-integer.

method get_second()

Synopsis

$result	= $datetime->get_second($format);

Return

MIXED Returns the second in a form depending on $format. Numeric values range from 0-59.

Arguments

ArgumentTypeDefaultDescription
$formatSTRING Specifies in what format the second is returned. Valid are following values:
-'alldigits': will return a padded number corresponding to the second
-'integer': will return the second as integer

Description

Return the second either as integer or as padded-integer.

method get_milli()

Synopsis

$result	= $datetime->get_milli($format);

Return

MIXED Returns the millisecond in a form depending on $format. Numeric values range from 0-999.

Arguments

ArgumentTypeDefaultDescription
$formatSTRING Specifies in what format the millisecond is returned. Valid are following values:
-'alldigits': will return a padded number corresponding to the millisecond
-'integer': will return the millisecond as integer

Description

Return the millisecond either as integer or as padded-integer.

method get_micro()

Synopsis

$result	= $datetime->get_micro($format);

Return

MIXED Returns the microsecond in a form depending on $format. Numeric values range from 0-999.

Arguments

ArgumentTypeDefaultDescription
$formatSTRING Specifies in what format the microsecond is returned. Valid are following values:
-'alldigits': will return a padded number corresponding to the microsecond
-'integer': will return the microsecond as integer

Description

Return the microsecond either as integer or as padded-integer.

method get_week()

Synopsis

$result	= $datetime->get_week($format);

Return

MIXED The week in a form depending on $format. Numeric values range from 1-53.

Arguments

ArgumentTypeDefaultDescription
$formatSTRING Specifies in what format the week is returned. Valid are following values:
-'alldigits': will return a padded number corresponding to the week
-'integer': will return the week as integer

Description

Return the week either as integer or as padded-integer.

method get_zodiac()

Synopsis

$result	= $datetime->get_zodiac();

Return

STRING localized name of the zodiac

Description

Returns the localized name of the zodiac for the datetime.

method get_age()

Synopsis

$result	= $datetime->get_age();

Return

INT The difference of total years between datetime and today.

Description

Returns the difference of total years between datetime and today.
Useful for usermanagements where you want to extract the age of somebody e.g.

method as_array()

Synopsis

$result	= $datetime->as_array();

Return

ARRAY An array containing all relevant values of datetime.

Description

Returns an array containing all relevant values of datetime.

method as_unixtime()

Synopsis

$result	= $datetime->as_unixtime();

Return

INT A unixtimestamp representation of datetime

Description

Returns a unixtimestamp representation of datetime

method as_mysqlDate()

Synopsis

$result	= $datetime->as_mysqlDate();

Return

STRING A string-representation of date-part of datetime ready for mysql-queries

Arguments

ArgumentTypeDefaultDescription
$asIntegerBOOL Return the value in the mysql-integer format for dates (yyyymmdd).

Description

Returns a string-representation of date-part of datetime ready for mysql-queries

method as_mysqlTime()

Synopsis

$result	= $datetime->as_mysqlTime($asInteger);

Return

STRING A string-representation of date-part of datetime ready for mysql-queries

Arguments

ArgumentTypeDefaultDescription
$asIntegerBOOL Return the value in the mysql-integer format for dates (HHMMSS).

Description

Returns a string-representation of date-part of datetime ready for mysql-queries

method as_mysqlDatetime()

Synopsis

$result	= $datetime->as_mysqlDatetime($asInteger);

Return

STRING A string-representation of datetime ready for mysql-queries

Arguments

ArgumentTypeDefaultDescription
$asIntegerBOOL Return the value in the mysql-integer format for dates (yyyymmddHHMMSS).

Description

Returns a string-representation of datetime ready for mysql-queries

method as_string()

Synopsis

$datetime	= new datetime();
echo $datetime->as_string("%m/%d/%Y %H.%M");
--> 11/21/2005 13.45
echo $datetime->as_string("%B %{B|lc} %{monthname|uc|3}");
--> November november NOV

Return

STRING The string containing the values as given in $pattern

Arguments

ArgumentTypeDefaultDescription
$patternSTRING How the string should be formatted, allowed are the two formats %<char>, %{string|modifier|...}.
See @chronos::get_stringPart() and @chronos::get_appliedModificators() for more informations about the formatting.

Description

Returns a formatted string of the datetime, comparable to strftime for unix-timestamps.
Be aware that the advanced syntax (%{part|modifier|...}) is quite powerful.

class difference

method difference()

Synopsis

$result	= $difference->difference($from, $difference, $timezone, $language);

Return

VOID Creates a new Object

Arguments

ArgumentTypeDefaultDescription
$fromSTRING One of the following values: 'string', 'array', 'exact' or 'nothing'
$differenceMIXED the difference to create the new object from, the format depends on $from.
$timezoneSTRING Either one of the timezone-id's like America/Los_Angeles (see data.locations.tab) or use a utc-name 'UTC±difference' like 'UTC', 'UTC+1' or 'UTC-4'. Timezone-IDs are prefered since they can determine the whished language, DST-behaviour and geographic position as well.
$languageSTRING An ISO 3166 two-letter-countrycode (like 'en', 'de' or 'fr'). The language parameter will override the setting retrieved from a timezone-ID. This can be useful if you want to print a date from another country but in your language.

Description

WARNING - This method is likely to change!
Creates a new difference object from $difference using create_fromString, create_fromArray or create_fromExact.
$timezone and $language are only needed if the object could become converted to a datetime (e.g. via addition of a datetime etc.). But you can set that after it become casted too if you want.
$difference should be an array of form array(seconds, months) if you set $from to 'exact'.

method create_fromString()

Synopsis

// this method is currently non-functional

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$stringTYPE description

Description

Creates

method create_fromPart()

Synopsis

$result	= $difference->create_fromPart($amount, $part);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$amountTYPE description
$partTYPE description

Description

description

method create_fromDatetimes()

Synopsis

$result	= $difference->create_fromDatetimes($datetime1, $datetime2);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$datetime1OBJECT Earlier datetime of the timespan from which you want to create the difference
$datetime2OBJECT Later datetime of the timespan from which you want to create the difference

Description

Creates a difference by subtracting $datetime1 from $datetime2.

method create_fromArray()

Synopsis

$result	= $difference->create_fromArray($array);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$arrayTYPE description

Description

description

method create_fromExact()

Synopsis

$result	= $difference->create_fromExact($seconds, $months);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$secondsTYPE description
$monthsTYPE description

Description

description

method do_add()

Synopsis

$result	= $difference->do_add($differenceDatetimeOrArray);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$differenceDatetimeOrArrayTYPE description

Description

description

method do_subtract()

Synopsis

$result	= $difference->do_subtract($differenceOrArray);

Return

BOOL Success

Arguments

ArgumentTypeDefaultDescription
$differenceOrArrayTYPE description

Description

description

method get_seconds()

Synopsis

$result	= $difference->get_seconds($part);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$partTYPE description

Description

description

method get_minutes()

Synopsis

$result	= $difference->get_minutes($part);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$partTYPE description

Description

description

method get_hours()

Synopsis

$result	= $difference->get_hours($part);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$partTYPE description

Description

description

method get_days()

Synopsis

$result	= $difference->get_days($part);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$partTYPE description

Description

description

method get_weeks()

Synopsis

$result	= $difference->get_weeks($part);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$partTYPE description

Description

description

method get_months()

Synopsis

$result	= $difference->get_months($part);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$partTYPE description

Description

description

method get_years()

Synopsis

$result	= $difference->get_years($part);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$partTYPE description

Description

description

method as_array()

Synopsis

$result	= $difference->as_array($part);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$partTYPE description

Description

description

method as_string()

Synopsis

$result	= $difference->as_string($pattern);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$patternTYPE description

Description

description

class timespan

method timespan()

Synopsis

$result	= $timespan->timespan($start, $end, $language, $timezone);

Return

VOID Creates a new Object

Arguments

ArgumentTypeDefaultDescription
$startTYPE description
$endTYPE description
$languageTYPE description
$timezoneTYPE description

Description

description

method count_weekdayOccurrences()

Synopsis

$result	= $timespan->count_weekdayOccurrences($day);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$dayTYPE description

Description

description

method count_monthOccurrences()

Synopsis

$result	= $timespan->count_monthOccurrences($month);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$monthTYPE description

Description

description

method count_weeks()

Synopsis

$result	= $timespan->count_weeks($mode);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$modeTYPE description

Description

description

class location

method location()

Synopsis

$result	= $location->location($location);

Return

VOID Creates a new Object

Arguments

ArgumentTypeDefaultDescription
$locationTYPE description

Description

description

method set_location()

Synopsis

$result	= $location->set_location($location);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$locationTYPE description

Description

description

method set_pseudoLocation()

Synopsis

$result	= $location->set_pseudoLocation($data);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$dataTYPE description

Description

description

method set_language()

Synopsis

$result	= $location->set_language($lang);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$langTYPE description

Description

description

method do_readData()

Synopsis

$result	= $location->do_readData($file);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$fileTYPE description

Description

description

method is_validID()

Synopsis

$result	= $location->is_validID($timezoneID);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$timezoneIDTYPE description

Description

description

method get_language()

Synopsis

$result	= $location->get_language();

Return

TYPE description

Description

description

method get_utc()

Synopsis

$result	= $location->get_utc();

Return

TYPE description

Description

description

method get_timezoneName()

Synopsis

$result	= $location->get_timezoneName($format);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$formatTYPE description

Description

description

method get_countryAlpha2()

Synopsis

$result	= $location->get_countryAlpha2();

Return

TYPE description

Description

description

method get_countryAlpha3()

Synopsis

$result	= $location->get_countryAlpha3();

Return

TYPE description

Description

description

method get_numeric()

Synopsis

$result	= $location->get_numeric();

Return

TYPE description

Description

description

method get_timezoneID()

Synopsis

$result	= $location->get_timezoneID();

Return

TYPE description

Description

description

method get_rawOffset()

Synopsis

$result	= $location->get_rawOffset();

Return

TYPE description

Description

description

method get_offset()

Synopsis

$result	= $location->get_offset($atDatetime);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$atDatetimeTYPE description

Description

description

method get_latitude()

Synopsis

$result	= $location->get_latitude($format);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$formatTYPE description

Description

description

method get_longitude()

Synopsis

$result	= $location->get_longitude($format);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$formatTYPE description

Description

description

method get_isDST()

Synopsis

$result	= $location->get_isDST($atDatetime);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$atDatetimeTYPE description

Description

description

method get_DSTrule()

Synopsis

$result	= $location->get_DSTrule();

Return

TYPE description

Description

description

class chronos

method chronos()

Synopsis

$result	= $chronos->chronos($timezoneID, $language);

Return

VOID Creates a new Object

Arguments

ArgumentTypeDefaultDescription
$timezoneIDTYPE description
$languageTYPE description

Description

description

method load_stringsFile()

Synopsis

$result	= $chronos->load_stringsFile($lang);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$langTYPE description

Description

description

method unset_dateTimeAndDifference()

Synopsis

$result	= $chronos->unset_dateTimeAndDifference();

Return

TYPE description

Description

description

method unset_time()

Synopsis

$result	= $chronos->unset_time();

Return

TYPE description

Description

description

method unset_date()

Synopsis

$result	= $chronos->unset_date();

Return

TYPE description

Description

description

method unset_difference()

Synopsis

$result	= $chronos->unset_difference();

Return

TYPE description

Description

description

method unset_differenceDate()

Synopsis

$result	= $chronos->unset_differenceDate();

Return

TYPE description

Description

description

method set_defaults()

Synopsis

$result	= $chronos->set_defaults($timezone);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$timezoneTYPE description

Description

description

method set_is()

Synopsis

$result	= $chronos->set_is($date, $time, $difference);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$dateTYPE description
$timeTYPE description
$differenceTYPE description

Description

description

method set_timezone()

Synopsis

$result	= $chronos->set_timezone($timezoneID);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$timezoneIDTYPE description

Description

description

method set_language()

Synopsis

$result	= $chronos->set_language($language);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$languageTYPE description

Description

description

method do_convertTimezone()

Synopsis

$result	= $chronos->do_convertTimezone($newTimezoneID);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$newTimezoneIDTYPE description

Description

description

method is_chronos()

Synopsis

$result	= $chronos->is_chronos($object, $class);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$objectTYPE description
$classTYPE description

Description

description

method is_time()

Synopsis

$result	= $chronos->is_time($exclusive, $object);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$exclusiveTYPE description
$objectTYPE description

Description

description

method is_date()

Synopsis

$result	= $chronos->is_date($exclusive, $object);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$exclusiveTYPE description
$objectTYPE description

Description

description

method is_datetime()

Synopsis

$result	= $chronos->is_datetime($object);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$objectTYPE description

Description

description

method is_dateOrTime()

Synopsis

$result	= $chronos->is_dateOrTime($object);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$objectTYPE description

Description

description

method is_difference()

Synopsis

$result	= $chronos->is_difference($object);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$objectTYPE description

Description

description

method is_leapyear()

Synopsis

$result	= $chronos->is_leapyear($year);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$yearTYPE description

Description

description

method is_dst()

Synopsis

$result	= $chronos->is_dst();

Return

TYPE description

Description

description

method is_equal()

Synopsis

$result	= $chronos->is_equal($to);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$toTYPE description

Description

description

method is_biggerOrEqual()

Synopsis

$result	= $chronos->is_biggerOrEqual($than);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$thanTYPE description

Description

description

method is_bigger()

Synopsis

$result	= $chronos->is_bigger($than);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$thanTYPE description

Description

description

method is_smallerOrEqual()

Synopsis

$result	= $chronos->is_smallerOrEqual($than);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$thanTYPE description

Description

description

method is_smaller()

Synopsis

$result	= $chronos->is_smaller($than);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$thanTYPE description

Description

description

method get_utc()

Synopsis

$result	= $chronos->get_utc($timezone);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$timezoneTYPE description

Description

description

method get_timezone()

Synopsis

$result	= $chronos->get_timezone($format);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$formatTYPE description

Description

description

method get_string()

Synopsis

$result	= $chronos->get_string($block, $string);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$blockTYPE description
$stringTYPE description

Description

description

method get_comparison()

Synopsis

$result	= $chronos->get_comparison($with);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$withTYPE description

Description

description

method get_cmp()

Synopsis

$result	= $chronos->get_cmp($with);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$withTYPE description

Description

description

method get_withoutOverflow()

Synopsis

$result	= $chronos->get_withoutOverflow($array);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$arrayTYPE description

Description

description

method get_differenceTo()

Synopsis

$result	= $chronos->get_differenceTo($to, $absolute);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$toTYPE description
$absoluteTYPE description

Description

description

method get_stringPart()

Synopsis

$result	= $chronos->get_stringPart($part);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$partTYPE description

Description

description

method get_timeserverStamp()

Synopsis

$result	= $chronos->get_timeserverStamp($server, $port);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$serverTYPE description
$portTYPE description

Description

description

method get_appliedModificators()

Synopsis

$result	= $chronos->get_appliedModificators($value, $modifiers);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$valueTYPE description
$modifiersTYPE description

Description

description

method get_sunCalculation()

Synopsis

$result	= $chronos->get_sunCalculation($location, $what, $timezone);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$locationTYPE description
$whatTYPE description
$timezoneTYPE description

Description

description

method include_exists()

Synopsis

$result	= $chronos->include_exists($filename);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$filenameTYPE description

Description

description

method convert_toDifference()

Synopsis

$result	= $chronos->convert_toDifference($ignoreDate);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$ignoreDateTYPE description

Description

description

method convert_toTime()

Synopsis

$result	= $chronos->convert_toTime();

Return

TYPE description

Description

description

method convert_toDate()

Synopsis

$result	= $chronos->convert_toDate();

Return

TYPE description

Description

description

method convert_toDatetime()

Synopsis

$result	= $chronos->convert_toDatetime($getMissingFrom, $value);

Return

TYPE description

Arguments

ArgumentTypeDefaultDescription
$getMissingFromTYPE description
$valueTYPE description

Description

description