| Declaration | |
| Datei | Dt.php |
| Date/Time modify File | 2024-01-29 09:22:54 |
| File-Size | 86 KByte |
| MD5 File | 2ca9ee977621b9508e421784a3419ea0 |
| Version | 2.3 (const VERSION = 2.3) |
| Date | 2023-03-03 |
| Methods and Parameter | Description/Comments |
|---|---|
| final public function __construct($dt = null, $timeZone = null) | new dt($dt, $timeZone) $dt: string or int/float timestamp or dt-object or DateTime-Object $timeZone. string or DateTimeZone.Object |
| public static function create(/* args */) | function returns a new dt-object or Bool false if Error first Arg: string or dt-object or DateTime-Object or float-Timestamp or int second Arg: last Arg: optional $timeZone as string or DateTimeZone.Object args */ |
| public static function createFromRegExFormat($regExFormats,$dateStr,$timeZone = null, $dateTemplate = 'today') | parse a string with a DateTime information with regular expressions regExFormat: string or array with regular Expressions dateStr: String with date information named identifier: <d> Tag, <m> Monat, <Y> Jahr(4 Ziff), <H> Stunde, <i> Minute, <s> Sekunde Example: '~^(?<d>\d{1,2})/(?<m>\d{1,2})/(?<y>\d\d)~'; timeZone: String or Object, NULL -> date_default_timezone_get() dateTemplate: String or Object, the template provides the missing information |
| public static function createDtFromFormat($formats, $time , $timeZone = null ) | Parses a time string according to a specified format $format string Format or array with formats $time string representing the time $timezone dateTimeZone object or string, defeault null for default Timezone Returns a new dt instance or FALSE on failure. |
| public static function createFromIntlFormat($format, $strDateTime , $timeZone = null, $language = null) | Parses a date-time string according to a specified Intl format $format string Format http://userguide.icu-project.org/formatparse/datetime $strDateTime string representing the time $timeZone dateTimeZone object or string, defeault null for default Timezone $language string locale-info Returns a new dt instance or FALSE on failure. |
| public static function timeStampFromIntlFormat($format, $strDateTime , $timeZone = null, $language = null) | Parses a date-time string according to a specified Intl format $format string Format $strDateTime string representing the time $timeZone dateTimeZone object or string, defeault null for default Timezone $language string locale-info Returns a timestamp or FALSE on failure. |
| public static function createFromJD($julianDateNumber, $timeZone = null ) | create dt from a Julian Date Number $julianDateNumber float Julian Date Number (Days since 1.Jan -4712 12:00) $timezone dateTimeZone object or string, defeault null for default Timezone Returns a new dt instance or FALSE on failure. |
| public static function createFromMsTimestamp($timestamp, $timeZone = "UTC" ) | create dt from a Microsoft Excel Timestamp (days since Dec 31 1899) @param float/Integer/string timestamp Microsoft Timestamp days since Dec 31 1899 If $timestamp is a string, a comma is replaced with a decimal point @param timezone dateTimeZone object or string, default is "UTC" , null for default Timezone @return new dt instance or FALSE on failure |
| public static function createFromSystemTime( $time, $basis = "1970-01-01", $resolution = 1.0, $timeZone = null ) |
create from System Time @param $time : date/time get from specific system @param $base : date/time for start epoch or range default 1970-01-01 Linux/Unix @param float $resolution: resolution of $time in seconds default 1 second @param timeZone, default default Timezone @return new dt instance or FALSE on failure |
| public function toGregorianFrom($calendar) | Convert date from Calendar to Gregorian @param string $calendar Japanese,Buddhist,Chinese,Persian,Indian,Islamic,Hebrew,Indian,Coptic,Ethiopic |
| public function getMsTimestamp() | get a Microsoft Timestamp (days since Dec 31 1899) @return float (days since Dec 31 1899) |
| public function copy() | clone self |
| public function getMatchLastCreateRegEx() | return last match Array from createFromRegExFormat return false, if instance not createt by createFromRegExFormat() |
| public static function setStrictModeCreate($OnOff = true) | set strict Mode for create if strict Mode set, Dt::create return false for invalid dates how 31 feb |
| public static function setDefaultLanguage($defaultLanguage = self::DE) | set DefaultLanguage 'en','de' used for format return: true ok, false if Error with a E_USER_WARNING |
| public static function getDefaultLanguage() | get DefaultLanguage how 'en','de' |
| public static function addLanguage($language, $nameList) | Dt::addLanguage @param string short language Name ("fr") @param string Name List "janvier,février,.." |
| public static function default_timezone_set($timezone) | default_timezone_set(string $timezone) alias for date_default_timezone_set() |
| public function formatL($format, $language = null) | returns a formatted date string param $language: 'en' or 'de' throw warnings |
| public function formatIntl($format = null, $language = null) | returns a formatted date string @param string $format: Intl ICU format @param string $language: en, de_AT, throw exeption if error |
| public function utcFormat($format = 'Y-m-d H:i:s') | returns a formatted date string @param string $format: default 'Y-m-d H:i:s' |
| public function setTime($par, $minute = null, $seconds = 0, $microseconds = NULL): self | set Time of day setTime('12:00'), setTime('12:00:05') setTime(13,30), setTime(13), setTime(13,15,45), setTime($date) //use time from $date |
| public function setDate($par=null, $month = null, $day = null): self | set Date or Year or Month or Day setDate('2000-1-1'), setDate('today') setDate(2000),setDate(null,1),setDate(null,1),setDate(null,null,1) setDate($date) set Date with Date-Part from $date |
| public function setDateTimeFrom(DateTime $dt) | set Date, Time and Timezone from dt or DateTime-Object @param DateTime $dt @return $this |
| public function setISOweek($week, $day = 1) | set Date to Week-number setISOweek(49) //Monday 49.Week, Year and Time not modify |
| public function setEasterDate($flag = self::EASTER_WEST) | set Date to Eastern 1600-1-1 < date < 2100-1-1 throw exeption if error |
| public function setPassoverDate() | set Date to first Day of Passover 1600-1-1 < date < 2100-1-1 throw Exception if error |
| public function getSunInfo($lat = null, $lon = null): array | get Sun Ifo of date @param $lat array [$lat, $lon] or float latitude @param $lon float Longitude @return array |
| public function setSunset($lat = null, $lon = null) | set Time to sunset of this Day @param $lat array [$lat, $lon, $zenith] or float latitude @param $lon float Longitude @param $zenith float zenith |
| public function setSunrise($lat = null, $lon = null) | set Time to sunrise of this Day @param $lat array [$lat, $lon, $zenith] or float latitude @param $lon float Longitude @param $zenith float zenith |
| public function setTimezone($timeZone = null): self | setTimezone(string Timezone), convert date in new Timezone Dt::create('24.12.2013 18:00')->setTimezone('America/New_York'); //12:00 America/New_York no $timeZone or NULL: default_timezone |
| public function isSummertime() | return true if Summertime |
| public function toCET() | toCET: set Timezone for CET return Standard-Time (Wintertime) |
| public function isWeekend() | return true if saturday or sunday |
| public function isWeekday() | return true if the day is from monday to friday |
| public function is($partialDateString) | is('datestring') @param string $partialDateString(|$partialDateString).. @return bool |
| public function isSameAs(string $dateFormat = 'YmdHis', $dt = 'Now') | isSameAs($dateFormat, $dateTime) compare this->format($dateFormat) with $dateTime->format($dateFormat) @param string $dateFormat @param mixed $dateTime: string, dt-object, DateTime-Object, int- or int-Timestamp @return bool |
| public function isCmp(string $op, $dt, string $dateFormatMask = 'YmdHisu') | compare this->format($dateFormat) with $dt->format($dateFormat) use operator $op @param string $op: =,!=,<,>,<=,>= @param mixed $dt: string, dt-object, DateTime-Object, int- or int-Timestamp @param string $dateFormatMask: any datetime format specification, def. 'YmdHisu' @return bool @throws Exception if invalid $op |
| public function isCurrent($dateFormat = 'YmdHis') | isCurrent($dateFormat) compare this->format($dateFormat) with now($dateFormat) @param string $dateFormat @return bool |
| public function isLeapYear() | return true if year is a leap year |
| public function isInWeek($dateWeek = null) | return true if the current Date is in $dateWeek param $dateWeek string or dt-object or DateTime-Object or int-Timestamp param null for Now return true/false or null if error |
| public function isTimeBetween(string $timeFrom, string $timeTo) : bool | return true if the time of Date is greater equal then $timeFrom and later then $timeTo @param string $timeFrom format H:i or H:i:s @param string $timeTo format H:i or H:i:s if $timeFrom > $timeTo -> Interval= $timefrom-24:00 and 00:00-$timeTo @return bool |
| public function isPast() | @return true if the current Date is <= now |
| public function isFuture() | @return true if the current Date is > now |
| public function isLastDayOfMonth() | @return true if the Date is last Day of the Month |
| public function getDaySeconds() | return integer Seconds since midnight |
| public function getDayMinutes() | return integer Minutes since midnight |
| public function getQuarter() | return numeric representation of the quarter (1..4) |
| public function age($timeToZero = false) | return int age = diff in years from date to now |
| public function average($refDate) | return the average Date between current Date and refDate |
| public function toDays() | return Count of Days after 0001-01-01 (+1 : counting the first day) Common Era (Gregorian) |
| public function toJD() | return float JD (Julian Date Number) |
| public function cut($interval=1, $round = false) | cut rest (floor number units) $Interval: number Seconds or String x Seconds, x Minutes, x Hours (reference 00:00) x days (reference first Day of Month), x weeks (reference 1900-01-01), x month , x years (reference year 0) round with $round = true example: Dt::create('2013-12-18 03:48')->cut('15 Minutes') //2013-12-18 03:45:00 |
| public function next($interval = '1 sec') | get DateTime to closest next interval $interval: number Seconds or String x Seconds, x Minutes, x Hours, x weeks, x month example: Dt::create('2013-12-18 03:38')->next('15 Minutes') //2013-12-18 03:45 |
| public function round($interval=1) | Round DateTime $interval: number Seconds or String x Seconds, x Minutes, x Hours, x weeks, x month example: Dt::create('2013-12-18 03:38')->round('15 Minutes') //2013-12-18 03:45:00 |
| public function getModulo($interval, $unitP = null) | get Modulo (Rest) after cut a Intervall return integer/float param string $interval (p.E. "5 Minutes") param string $unit: Week, Day, Hour, Minute, Second, Year, Month default $unit get from Interval |
| public function min(...$dates) | provides a copy of the smallest date @param $dates : a array of dates or date1,[date2,..] @return: dt-object |
| public function max(...$dates) | provides a copy of the biggest date @param $dates : a array of dates or date1,[date2,..] @return: dt-object |
| public function diff($date = null, $absolute = false): DateInterval | return DateInterval object diff accept as parameter object, string or timestamp |
| public function diffTotal($date=null, $unitP = "sec",$monthDependWeighting = false) | diffTotal return a difference as int/float in the selected unit $date: string or objekt DateTime $unit: Week, Day, Hour, Minute, Second, Year, Month for Year and Month return full Years or Month (integer) |
| public function diffHuman($date=null, $language = null) | diffHuman return a difference as human readable string example "3 Month" $date: string, objekt DateTime or int/float Timestamp $language: 'de','en' |
| public function diffUTC($date, $unitP = "sec") | diffUTC return the real time differenz as float fractions of seconds as decimal $date: string or objekt DateTime $unit: Hour, Minute, Second |
| public function diffFormat($date , $format) | calculates the difference and formats the result supports microseconds for php >= 7.1 @param mixed $date @param mixed $format: DateInterval::formats + %G, %v @return string or bool false if error |
| public function countDaysTo($dayIdentList, $dateTo, $excludeDateTo = false) | get count of speciific weekdays between dates @param mixed $dayIdentList (int 0=Sun .. 6 =Sat or string 'Sun','Mon'..'Sat' or rel.DateString or DateString or a comma separated list null or 'all' is a short for '0,1,2,3,4,5,6' @param mixed $dateTo: string, timestamp or object @param bool $excludeDateTo exclude the top Date $return int, bool false if error |
| public function chain($chainModifier, array $para = array()) | modify with a chain of modifier separated with | $chainModifier : modifier-list $para : Array with optional parameters |
| public static function totalRelTime($relTime, $unit = 'sec', $basis = '2000-1-1') | return int/float value in the selected unit from a relativ Time or a DateInterval-Object or number Seconds or time-string 00:03:04.7 return false if error unit: 's','m','h','d','w' return float unit: 'y','mo(nth)' return int basis: date basis, date reference: used for month and years in Time Dt::totalRelTime('1 week','days'); //7 |
| public static function timeToSeconds($timeString) | timeStrToSeconds: Convert a string "ii:ss,ms" to Seconds (Float) @param string time: hhh:ii hhh:ii:ss hhh:ii.ss,m ii:ss.m >= v1.95 accept negative times return Float or bool false if error |
| public static function date_interval_create_from_float($timeValue, $unitP = "Second") | Calculated from a value (int / float) and a unit a DateInterval support microseconds for PHP >= 7.1 unitP: 'week', 'day','hour','minute','second' return DateInterval-Object , false bei Fehler |
| public static function formatDateInterval($format, DateInterval $dateInterval) | formats a DateInterval @param string $format: DateInterval::formats + %G, %v, %w (full weeks!) @param DateInterval $dateInterval @return string |
| public function __toString() | Dateformat for Output (echo) and string casting |
| public function toStringWithMicro() | Format the instance as 'Y-m-d H:i:s.u' |
| public function getDateTime() | get dt as new DateTime (copy) |
| public function getMicroSeconds() | return the Microseconds from DateTime |
| public function setMicroSeconds($microSeconds) | set microSeconds $microSeconds (Integer) : microSeconds |
| public function setSecond($newSecond = 0) | set second ($newSecond Integer) and MicroSeconds $param newSecond integer, float or dt, datetime Object |
| public function setMinute($newMinute = 0) | set only minute $param $newMinute integer, float or dt, datetime Object |
| public function setHour($newHour = 0) | set only hour $param $newHour integer, float or dt, datetime Object |
| public function setYear($newYear = false) | set only the year $param $newYear integer, float or dt, datetime Object or bool if true then the current or the following year is set so that the value lies in the future if false Parameter set current year (Default) |
| public function getMicroTime() | get a float Timestamp |
| public function setTimestamp($unixtimestamp): self | set DateTime from int/float-Timestamp |
| public function addMonthCut($month = 1) | adds a number of months and cut supernumerary Result is always in the current month as DATE_ADD MySQL 2014-1-31 + 1 Month -> 2014-02-28 2014-3-30 - 1 Month -> 2014-02-28 |
| public function addTime($timeInterval) | add a relative Time ('1 Hour', '05:03', '00:00:03.5') accept also DateInterval, but DateTime::add is better accept "-10:44" > v 1.89 |
| public function subTime($timeInterval) | sub a relative Time ('1 Hour', '05:03', '00:00:03.5') accept also DateInterval, but DateTime::sub is better |
| public function addSeconds($seconds) | add a number of Seconds (Int/Float) throw exception if error negative values are permissible |
| function addDays($dayNumber,$dayIdentList = "all",$filter = "") | Adds daynumber days to the date. Only the days of the week that are in $dayIdentList are counted. @param $dayNumber > 0 @param mixed $dayIdentList (int 0=Sun .. 6 =Sat or string 'Sun','Mon'..'Sat' or rel.DateString or DateString or a comma separated list null or 'all' is a short for '0,1,2,3,4,5,6' @param $filter optional filter function $return $this |
| public function isCron($cronStr) | check if cron expression match @return true if dateTime match cron expression @return null if ERROR @para $cronStr cron-expression e.g "15 * * * *" |
| public function nextCron($cronStr) | get the next run date of a cron expression @return dt if error return 1970-01-01, isError() return true, more Info with getErrorInfo() @para $cronStr cron-expression e.g "15 * * * *" |
| public function previousCron($cronStr) | get the previous run date of a cron expression @return dt if error return 1970-01-01, isError() return true, more Info with getErrorInfo() @para $cronStr cron-expression e.g "15 * * * *" |
| public function toCron() | get a cron string from datetime @return string |
| public function setClockChange($toWintertime = false) | @return: DateTime of Clockchange to Summertime ($toWintertime = false) or to Wintertime, null if no Clockchange or false if error @params: $toWintertime false or true @params: $timeZone string or timezoneobject |
| public static function getClockChange($year, $toWintertime = false, $timeZone = null) | @return: DateTime of Clockchange to Summertime ($toWintertime = false) or to Wintertime, null if no Clockchange or false if error @params: $year as YYYY, max. 2037 @params: $toWintertime false or true @params: $timeZone string or timezoneobject |
| public static function Easter($year, $flag = self::EASTER_WEST) | create Easter-Date for a given year $year : integer $flag : Dt::EASTER_WEST or Dt::EASTER_EAST return dt object or false if error |
| public static function Passover($year) | calculate the first full day of Passover (Gauß) @params: $year integer as YYYY, interval 1900 to 2099 |
| public static function getEquinox($year,$timeZone = null) | calculate Equinox (Äquinoktium primär) approximate formula @params: $year integer as YYYY @params: string/object $timezone @return date Object |
| public function isError() | returns true if an error or a warning is present |
| public function getErrorInfo() | return Errors and Warnings as a string of the form "A parse date what invalid (w)" return empty string if no error |
| public static function getLastErrorsAsString() | return the last Date/Time error as string (w) warning, (e) error |
| public function __get($name) | Get a property of dt @param string $name @return mixed, throw LogicException if error Propertys @property int $second : format('s') @property int $minute : format('i') @property int $hour : format('G') @property int $day : format('j') @property int $month : format('n') @property int $year : format('Y') @property int $microsecond : format('u') @property int $dayOfWeek : format('N') @property int $weekOfYear : format('W') @property int $daysInMonth : format('t') @property string $dayName : format('D') Mon..Sun @property string $fullDayName : format('l') Mon..Sun @property int $dayOfYear : format('z') + 1 @property int $weekOfMonth : start with 1 @property int $weekOf1900 : number of weeks from 1900-01-01 start at 1 @property string $tzName : Timezone Name @property int $tzType : Timezone type |
| public function __sleep() | Returns the list of properties to dump on serialize() called on. @return array |
| public static function createLanguageConfig($locale = "de") | create array for language translation @param $locale string language 'fr','it'.. @return string with config or false if error |
| public static function translateMonth($strDate) | swaps month from defaultLanguage from StrDate -> Eng. Dt::translateMonth("3. Mai 1985") -> ""3. May 1985"" return string if ok, otherwise false |
| public static function modifyToEaster(Dt $dt, $year, $flag = self::EASTER_WEST) | helper for Easter-Date $dt : dt object $year : integer $flag : Dt::EASTER_WEST or Dt::EASTER_EAST return dt object or false if error |
| public static function searchDateTimeZone($name, $allAsArray = false) | get DateTimeZone from name fragment or country code @param: string $name, countrycode how "de" or fragment how 'berlin' @param: bool $allAsArray, default false return 1 result or false as error $allAsArray true return array @return: mixed string|array|bool |
| public static function getTranslateArray($language = null) | for Test and Development |
| Declaration/Name | Value | Description/Comments |
|---|---|---|
| const VERSION = '2.3'; | '2.3' | |
| const EN_PHP = 'en_php'; | 'en_php' | |
| const EN = 'en'; | 'en' | |
| const DE = 'de'; | 'de' | |
| const EASTER_WEST = CAL_EASTER_ALWAYS_GREGORIAN; | 2 | |
| const EASTER_EAST = CAL_EASTER_ALWAYS_JULIAN; //Orthodox | 3 | Orthodox |
| const TO_STRING_FORMAT = 'Y-m-d H:i:s'; | 'Y-m-d H:i:s' | |
| const DATE2000Z2 = 40; //yy < DATE2000Z2 -> 20yy | 40 | yy < DATE2000Z2 -> 20yy |
| const PAGE_ENCODING = 'UTF-8'; | 'UTF-8' | |
| ATOM | 'Y-m-d\TH:i:sP' | * Inherit |
| COOKIE | 'l, d-M-Y H:i:s T' | * Inherit |
| ISO8601 | 'Y-m-d\TH:i:sO' | * Inherit |
| ISO8601_EXPANDED | 'X-m-d\TH:i:sP' | * Inherit |
| RFC822 | 'D, d M y H:i:s O' | * Inherit |
| RFC850 | 'l, d-M-y H:i:s T' | * Inherit |
| RFC1036 | 'D, d M y H:i:s O' | * Inherit |
| RFC1123 | 'D, d M Y H:i:s O' | * Inherit |
| RFC7231 | 'D, d M Y H:i:s \G\M\T' | * Inherit |
| RFC2822 | 'D, d M Y H:i:s O' | * Inherit |
| RFC3339 | 'Y-m-d\TH:i:sP' | * Inherit |
| RFC3339_EXTENDED | 'Y-m-d\TH:i:s.vP' | * Inherit |
| RSS | 'D, d M Y H:i:s O' | * Inherit |
| W3C | 'Y-m-d\TH:i:sP' | * Inherit |