-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Thiago Delgado Pinto edited this page Oct 22, 2016
·
6 revisions
#TDateTime
There are three available classes: TDateTime
, TDate
, and TTime
. The first one inherits from PHP's \DateTime
and it is the parent class of TDate
and TTime
. Thus, TDateTime
is compatible with DateTime
and can replace it. Its child classes just change the formatting methods, such as toString()
and toDatabaseFormat()
in order to facilitate the conversion to string or their storage into databases.
The following methods are the main methods in TDateTime
. Please check the class for all available methods.
-
int year()
gets the year; -
TDateTime& setYear( int $year )
sets the year. This method is chainnable; -
bool isLeapYear()
returnstrue
/false
if the year is a leap year; -
TDateTime& addYears( int $years )
adds years to the current date. This method is chainnable; -
TDateTime& addOneYear()
adds one year to the current date. This method is chainnable; -
TDateTime& plusYears( int $years )
same asaddYears()
; -
TDateTime& plusOneYear()
same asaddOneYear()
; -
TDateTime& subYears( int $years )
subtracts years from the current date. This method is chainnable; -
TDateTime& subOneYear()
subtracts one year from the current date. This method is chainnable; -
TDateTime& minusYears( int $years )
same assubYears()
; -
TDateTime& minusOneYear()
same assubOneYear()
;
-
int month()
gets the month; -
void setMonth( int $month )
sets the month. This method is chainnable; -
int daysInMonth()
returns the number of the days in the date's month; -
TDateTime& addMonths( int $months )
adds$month
times30
days. This method is chainnable; -
TDateTime& addOneMonth()
adds30
days. This method is chainnable; -
TDateTime& plusMonths( int $months )
same asaddMonths()
; -
TDateTime& plusOneMonth()
same asplusMonths()
; -
TDateTime& subMonths( int $months )
substracts$month
times30
days. This method is chainnable; -
TDateTime& subOneMonth()
subtracts30
days. This method is chainnable; -
TDateTime& minusMonths( int $months )
same assubMonths()
; -
TDateTime& minusOneMonth()
same assubOneMonth()
;
-
int day()
returns the day (int
); -
TDateTime& setDay( int $day )
sets the day. This method is chainnable; -
int dayOfYear()
returns the day of the year (int
, from1
to356
); -
int dayOfWeek()
returns the day of the week (int
, from0
to6
where0
is Sunday); -
int weekOfYear()
returns the week of the year. According to ISO-8601, weeks start on Monday; -
double age( \DateTime $currentDate = null )
returns the age of a person. By default, it considers today as the current date. You can specify the current date for the calculus; -
bool isSunday()
returnstrue
if the date is a sunday; -
bool isSaturday()
returnstrue
if the date is a saturday; -
bool isWeekend()
returnstrue
if the date is a sunday or a saturday; -
TDateTime& addDays( $days )
adds the given number of days. This method is chainnable; -
TDateTime& addOneDay()
adds one day. This method is chainnable; -
TDateTime& plusDays( $days )
same asaddDays()
; -
TDateTime& plusOneDay()
same asaddOneDay()
; -
TDateTime& subDays( $days )
subtracts the given number of days. This method is chainnable; -
TDateTime& subOneDay()
subtracts one day. This method is chainnable; -
TDateTime& minusDays( $days )
same assubDays()
; -
TDateTime& minusOneDay()
same assubOneDay()
;
-
int hour()
gets the hour; -
TDateTime& setHour( int $hour )
sets the hour. This method is chainnable; -
bool isAm()
returnstrue
if the hour is ante meridiem; -
bool isPm()
returnstrue
if the hour is post meridiem; -
bool isDaylightSavingTime()
returnstrue
if the time is in daylight saving; -
int utcOffset()
returns the UTF offset considering day light saving; -
string timezoneName()
returns the timezone name; -
TDateTime& addHours( int $hours )
adds the given number of hours. This method is chainnable; -
TDateTime& addOneHour()
adds one hours. This method is chainnable; -
TDateTime& plusHours( int $hours )
same asaddHours()
; -
TDateTime& plusOneHour()
same asaddOneHour()
; -
TDateTime& subHours( int $hours )
subtracts the given number of hours. This method is chainnable; -
TDateTime& subOneHour()
subtracts one hours. This method is chainnable; -
TDateTime& minusHours( int $hours )
same assubHours()
; -
TDateTime& minusOneHour()
same assubOneHour()
;
-
int minute()
gets the minute; -
TDateTime& setMinute( int $minute )
sets the minute. This method is chainnable; -
TDateTime& addMinutes( int $minutes )
adds the given minutes. This method is chainnable; -
TDateTime& addOneMinute()
adds one minute. This method is chainnable; -
TDateTime& plusMinutes( int $minutes )
same asaddMinutes()
; -
TDateTime& plusOneMinute()
same asaddOneMinute()
; -
TDateTime& subMinutes( int $minutes )
subtracts the given minutes. This method is chainnable; -
TDateTime& subOneMinute()
subtracts one minute. This method is chainnable; -
TDateTime& minusMinutes( int $minutes )
same assubMinute()
; -
TDateTime& minusOneMinute()
same assubOneMinute()
;
-
int second()
gets the second; -
TDateTime& setSecond( int $second )
sets the second. This method is chainnable; -
TDateTime& addSeconds( int $seconds )
adds the given seconds. This method is chainnable; -
TDateTime& addOneSecond()
adds one second. This method is chainnable; -
TDateTime& plusSeconds( int $seconds )
same asaddSeconds
; -
TDateTime& plusOneSecond()
same asaddOneSecond
; -
TDateTime& subSeconds( int $seconds )
subtracts the given seconds. This method is chainnable; -
TDateTime& subOneSecond()
subtracts one second. This method is chainnable; -
TDateTime& minusSeconds( int $seconds )
same assubSeconds
; -
TDateTime& minusOneSecond()
same assubOneSecond
;
-
int micro()
gets the microtime;
-
int|double diffInYears( \DateTime $dateTime, $absolute = true )
returns the difference in years from a given\DateTime
. If absolute is true, it returns an integer value. Otherwise a double value; -
int|double diffInMonths( \DateTime $dateTime, $absolute = true )
returns the difference in months from a given\DateTime
. If absolute is true, it returns an integer value. Otherwise a double value; -
int|double diffInDays( \DateTime $dateTime, $absolute = true )
returns the difference in days from a given\DateTime
. If absolute is true, it returns an integer value. Otherwise a double value; -
int|double diffInWeeks( \DateTime $dateTime, $absolute = true )
returns the difference in weeks from a given\DateTime
. If absolute is true, it returns an integer value. Otherwise a double value; -
int|double diffInHours( \DateTime $dateTime, $absolute = true )
returns the difference in hours from a given\DateTime
. If absolute is true, it returns an integer value. Otherwise a double value; -
int|double diffInMinutes( \DateTime $dateTime, $absolute = true )
returns the difference in minutes from a given\DateTime
. If absolute is true, it returns an integer value. Otherwise a double value; -
int|double diffInSeconds( \DateTime $dateTime, $absolute = true )
returns the difference in seconds from a given\DateTime
. If absolute is true, it returns an integer value. Otherwise a double value;
-
TDateTime& clearDate()
clears the date part of the datetime; -
TDateTime& clearTime()
clears the time part of the datetime; -
TDateTime& clear()
clear the date and time; -
TDateTime& copyDate( \DateTime $dateTime )
copy the date part of a\DateTime
; -
TDateTime& copyTime( \DateTime $dateTime )
copy the time part of a\DateTime
; -
TDateTime& copyDateTime( \DateTime $dateTime )
copy a\DateTime
; -
TDateTime& copy( \DateTime $dateTime )
same ascopyDateTime()
; -
TDateTime newCopy()
creates a copy of the current instance;
-
bool after( \DateTime $dateTime )
; -
bool before( \DateTime $dateTime )
; -
bool between( \DateTime $min, \DateTime $max )
; -
bool greaterThan( \DateTime $dateTime )
; -
bool greaterThanOrEqualTo( \DateTime $dateTime )
; -
bool lessThan( \DateTime $dateTime )
; -
bool lessThanOrEqualTo( \DateTime $dateTime )
; -
bool equalTo( \DateTime $dateTime )
; -
bool notEqualTo( \DateTime $dateTime )
;
-
string toString()
; -
string dateString()
; -
string timeString()
; -
string simpleTimeString()
; -
TDateTime& fromString( string $text, \DateTimeZone $timezone = null )
; -
TDateTime& fromDateString( string $text, \DateTimeZone $timezone = null )
; -
TDateTime& fromTimeString( string $text, \DateTimeZone $timezone = null )
; -
TDateTime& fromSimpleTimeString(string $text, \DateTimeZone $timezone = null )
; -
TDateTime& fromDateTime( \DateTime $dateTime )
; -
TDateTime& parse( string $format , $time, \DateTimeZone $timezone = null )
;
-
string toDatabaseString()
; -
string toDatabaseDateString()
; -
string toDatabaseTimeString()
; -
string toDatabaseSimpleTimeString()
; -
TDateTime& fromDatabaseString( string $text, \DateTimeZone $timezone = null )
; -
TDateTime& fromDatabaseDateString( string $text, \DateTimeZone $timezone = null )
; -
TDateTime& fromDatabaseTimeString( string $text, \DateTimeZone $timezone = null )
; -
string toBrazilianString()
; -
string toBrazilianDateString()
; -
string toBrazilianTimeString()
; -
string toBrazilianSimpleTimeString()
; -
TDateTime& fromBrazilianString( string $text, \DateTimeZone $timezone = null )
; -
TDateTime& fromBrazilianDateString( string $text, \DateTimeZone $timezone = null )
; -
TDateTime& fromBrazilianTimeString( string $text, \DateTimeZone $timezone = null )
; -
TDateTime& fromBrazilianSimpleTimeString( string $text, \DateTimeZone $timezone = null )
; -
string toAmericanString()
; -
string toAmericanDateString()
; -
string toAmericanTimeString()
; -
string toAmericanSimpleTimeString()
; -
TDateTime& fromAmericanString( string $text, \DateTimeZone $timezone = null )
; -
TDateTime& fromAmericanDateString( string $text, \DateTimeZone $timezone = null )
; -
TDateTime& fromAmericanTimeString( string $text, \DateTimeZone $timezone = null )
; -
TDateTime& fromAmericanSimpleTimeString( string $text, \DateTimeZone $timezone = null )
;
-
bool isValidTime( string $time, string $separator = ':' )
; -
bool isValidSimpleTime( string $time, string $separator = ':' )
; -
bool isValidDatabaseDateTime( string $dateTime, string $dateSeparator = '/', string $timeSeparator = ':' )
; -
bool isValidDatabaseDate( string $date, string $separator = '/' )
; -
bool isValidAmericanDateTime( string $dateTime, string $dateSeparator = '/', string $timeSeparator = ':' )
; -
bool isValidAmericanDate( string $date, string $separator = '/' )
; -
bool isValidBrazilianDateTime( string $dateTime, string $dateSeparator = '/', string $timeSeparator = ':' )
; -
bool isValidBrazilianDate( string $date, string $separator = '/' )
;
Days of week:
-
SUNDAY
= 0; -
MONDAY
= 1; -
TUESDAY
= 2; -
WEDNESDAY
= 3; -
THURSDAY
= 4; -
FRIDAY
= 5; -
SATURDAY
= 6;
Conversions:
-
MONTHS_PER_YEAR
= 12; -
WEEKS_PER_MONTH
= 4; -
DAYS_PER_WEEK
= 7; -
SECONDS_PER_MINUTE
= 60; -
MINUTES_PER_HOUR
= 60;
Formats:
-
DATABASE_DATETIME_FORMAT
= 'Y-m-d H:i:s'; -
DATABASE_DATE_FORMAT
= 'Y-m-d'; -
DATABASE_TIME_FORMAT
= 'H:i:s'; -
DATABASE_SIMPLE_TIME_FORMAT
= 'H:i'; -
AMERICAN_DATETIME_FORMAT
= 'm/d/Y H:i:s'; -
AMERICAN_DATE_FORMAT
= 'm/d/Y'; -
AMERICAN_TIME_FORMAT
= 'H:i:s'; -
AMERICAN_SIMPLE_TIME_FORMAT
= 'H:i'; -
BRAZILIAN_DATETIME_FORMAT
= 'd/m/Y H:i:s'; -
BRAZILIAN_DATE_FORMAT
= 'd/m/Y'; -
BRAZILIAN_TIME_FORMAT
= 'H:i:s'; -
BRAZILIAN_SIMPLE_TIME_FORMAT
= 'H:i';