Copied!

Zap Calendar Date Helper Class

Helper class for various date functions

Cloneable Instantiable
Methods
public static addDate ( int $date , int $hour , int $min , int $sec , int $month , int $day , int $year , string $tzid = 'UTC' )
 

Date math: add or substract from current date to get a new date

  • param int $date date to add or subtract from
  • param int $hour add or subtract hours from date
  • param int $min add or subtract minutes from date
  • param int $sec add or subtract seconds from date
  • param int $month add or subtract months from date
  • param int $day add or subtract days from date
  • param int $year add or subtract years from date
  • param string $tzid PHP recognized timezone (default is UTC)
  • return int Unix timestamp
public static DayInMonth ( int $month , int $year ) : int
 

Find the number of days in a month

  • param int $month Month is between 1 and 12 inclusive
  • param int $year is between 1 and 32767 inclusive
public static DTNow ( string $tzid ) : DateTime
 

Return now as DateTime

  • param string $tzid PHP recognized timezone (default is UTC)
  • return DateTime
public static fromiCaltoUnixDateTime ( string $datetime ) : int
 

Format iCal date-time string to Unix timestamp

  • param string $datetime in iCal time format ( YYYYMMDD or YYYYMMDDTHHMMSS or YYYYMMDDTHHMMSSZ )
  • return int Unix timestamp
public static fromSqlDateTime ( ? string $datetime = NULL ) : string
 

fromSqlDateTime()

Take SQL timestamp and format to iCal date/time string

  • param string $datetime SQL timestamp, leave blank for current date/time
  • return string formatted iCal date/time string
public static fromUnixDate ( ? int $datetime = NULL ) : string
 

fromUnixDate()

Take Unix timestamp and format to iCal date string

  • param int $datetime Unix timestamp, leave blank for current date/time
  • return string formatted iCal date string
public static fromUnixDateTime ( ? int $datetime = NULL ) : string
 

fromUnixDateTime()

Take Unix timestamp and format to iCal date/time string

  • param int $datetime Unix timestamp, leave blank for current date/time
  • return string formatted iCal date/time string
public static fromUnixDateTimetoiCal ( int $datetime ) : string
 

Format Unix timestamp to iCal date-time string

  • param int $datetime Unix timestamp
public static getAbsDate ( string $date , string $rdate = '' ) : string
 

Convert from a relative date to an absolute date

Examples of relative dates are '-2y' for 2 years ago, '18m'
for 18 months after today. Relative date uses 'y', 'm' and 'd' for
year, month and day. Relative date can be combined into comma
separated list, i.e., '-1y,-1d' for 1 year and 1 day ago.

  • param string $date relative date string (i.e. '1y' for 1 year from today)
  • param string $rdate reference date, or blank for current date (in SQL date-time format)
  • return string in SQL date-time format
public static getDateFromDay ( int $date , int $week , int $wday , string $tzid = 'UTC' ) : int
 

Date math: get date from week and day in specific month

This routine finds actual dates for the second Tuesday of the month, last Friday of the month, etc.
For second Tuesday, use $week = 1, $wday = 2
for last Friday, use $week = -1, $wday = 5

  • param int $date Unix timestamp
  • param int $week week number, 0 is first week, -1 is last
  • param int $wday day of week, 0 is Sunday, 6 is Saturday
  • param string $tzid PHP supported timezone
  • return int Unix timestamp
public static iCalDurationtoSeconds ( string $duration ) : int
 

Convert iCal duration string to # of seconds

  • param string $duration iCal duration string
public static inDay ( int $daystart , int $begin , int $end ) : bool
 

Check if day falls within date range

  • param int $daystart start of day in Unix timestamp format
  • param int $begin Unix timestamp of starting date range
  • param int $end Unix timestamp of end date range
public static isAfterToday ( int $date , string $tzid = 'UTC' ) : bool
 

Is given date after today?

  • param int $date date in Unix timestamp format
  • param string $tzid PHP recognized timezone (default is UTC)
public static isBeforeToday ( int $date , string $tzid = 'UTC' ) : bool
 

Is given date before today?

  • param int $date date in Unix timestamp format
  • param string $tzid PHP recognized timezone (default is UTC)
public static isFuture ( int $date , string $tzid = 'UTC' ) : bool
 

Is given date in the future?

This routine differs from isAfterToday() in that isFuture() will
return true for date-time values later in the same day.

  • param int $date date in Unix timestamp format
  • param string $tzid PHP recognized timezone (default is UTC)
public static isPast ( int $date , string $tzid = 'UTC' ) : bool
 

Is given date in the past?

This routine differs from isBeforeToday() in that isPast() will
return true for date-time values earlier in the same day.

  • param int $date date in Unix timestamp format
  • param string $tzid PHP recognized timezone (default is UTC)
public static isToday ( int $date , string $tzid = 'UTC' ) : bool
 

Is given date today?

  • param int $date date in Unix timestamp format
  • param string $tzid PHP recognized timezone (default is UTC)
public static isTomorrow ( int $date , string $tzid = 'UTC' ) : bool
 

Is given date tomorrow?

  • param int $date date in Unix timestamp format
  • param string $tzid PHP recognized timezone (default is UTC)
public static isWeekend ( int $date ) : bool
 

Is given date fall on a weekend?

  • param int $date Unix timestamp
public static now ( string $tzid = 'UTC' ) : int
 

Return current Unix timestamp in local timezone

  • param string $tzid PHP recognized timezone
public static toiCalDate ( ? int $datetime = NULL ) : string
 

Format Unix timestamp to iCal date format

  • param int $datetime Unix timestamp
  • return string iCal date-time string
public static toiCalDateTime ( ? int $datetime = NULL ) : string
 

Format Unix timestamp to iCal date-time format

  • param int $datetime Unix timestamp
  • return string iCal date-time string
public static toLocalDateTime ( string $sqldate , string $tzid = 'UTC' ) : string
 

Convert UTC date-time to local date-time

  • param string $sqldate SQL date-time string
  • param string $tzid PHP recognized timezone (default is 'UTC')
  • return string SQL date-time string
public static toSQLDate ( int $t = 0 ) : string
 

Format Unix timestamp to SQL date

  • param int $t Unix timestamp
public static toSQLDateTime ( int $t = 0 ) : string
 

Format Unix timestamp to SQL date-time

  • param int $t Unix timestamp
public static toUnixDate ( string $datetime ) : int
 

Convert SQL date or date-time to Unix timestamp

  • param string $datetime SQL date or date-time
  • return int Unix date-time timestamp
public static toUnixDateTime ( string $datetime ) : int
 

Convert SQL date or date-time to Unix date timestamp

  • param string $datetime SQL date or date-time
  • return int Unix timestamp
public static toUTCDateTime ( string $sqldate , string $tzid = 'UTC' ) : string
 

Convert local date-time to UTC date-time

  • param string $sqldate SQL date-time string
  • param string $tzid PHP recognized timezone (default is 'UTC')
  • return string SQL date-time string
Methods
public static addDate ( int $date , int $hour , int $min , int $sec , int $month , int $day , int $year , string $tzid = 'UTC' )
 

Date math: add or substract from current date to get a new date

  • param int $date date to add or subtract from
  • param int $hour add or subtract hours from date
  • param int $min add or subtract minutes from date
  • param int $sec add or subtract seconds from date
  • param int $month add or subtract months from date
  • param int $day add or subtract days from date
  • param int $year add or subtract years from date
  • param string $tzid PHP recognized timezone (default is UTC)
  • return int Unix timestamp
public static DayInMonth ( int $month , int $year ) : int
 

Find the number of days in a month

  • param int $month Month is between 1 and 12 inclusive
  • param int $year is between 1 and 32767 inclusive
public static DTNow ( string $tzid ) : DateTime
 

Return now as DateTime

  • param string $tzid PHP recognized timezone (default is UTC)
  • return DateTime
public static fromiCaltoUnixDateTime ( string $datetime ) : int
 

Format iCal date-time string to Unix timestamp

  • param string $datetime in iCal time format ( YYYYMMDD or YYYYMMDDTHHMMSS or YYYYMMDDTHHMMSSZ )
  • return int Unix timestamp
public static fromSqlDateTime ( ? string $datetime = NULL ) : string
 

fromSqlDateTime()

Take SQL timestamp and format to iCal date/time string

  • param string $datetime SQL timestamp, leave blank for current date/time
  • return string formatted iCal date/time string
public static fromUnixDate ( ? int $datetime = NULL ) : string
 

fromUnixDate()

Take Unix timestamp and format to iCal date string

  • param int $datetime Unix timestamp, leave blank for current date/time
  • return string formatted iCal date string
public static fromUnixDateTime ( ? int $datetime = NULL ) : string
 

fromUnixDateTime()

Take Unix timestamp and format to iCal date/time string

  • param int $datetime Unix timestamp, leave blank for current date/time
  • return string formatted iCal date/time string
public static fromUnixDateTimetoiCal ( int $datetime ) : string
 

Format Unix timestamp to iCal date-time string

  • param int $datetime Unix timestamp
public static getAbsDate ( string $date , string $rdate = '' ) : string
 

Convert from a relative date to an absolute date

Examples of relative dates are '-2y' for 2 years ago, '18m'
for 18 months after today. Relative date uses 'y', 'm' and 'd' for
year, month and day. Relative date can be combined into comma
separated list, i.e., '-1y,-1d' for 1 year and 1 day ago.

  • param string $date relative date string (i.e. '1y' for 1 year from today)
  • param string $rdate reference date, or blank for current date (in SQL date-time format)
  • return string in SQL date-time format
public static getDateFromDay ( int $date , int $week , int $wday , string $tzid = 'UTC' ) : int
 

Date math: get date from week and day in specific month

This routine finds actual dates for the second Tuesday of the month, last Friday of the month, etc.
For second Tuesday, use $week = 1, $wday = 2
for last Friday, use $week = -1, $wday = 5

  • param int $date Unix timestamp
  • param int $week week number, 0 is first week, -1 is last
  • param int $wday day of week, 0 is Sunday, 6 is Saturday
  • param string $tzid PHP supported timezone
  • return int Unix timestamp
public static iCalDurationtoSeconds ( string $duration ) : int
 

Convert iCal duration string to # of seconds

  • param string $duration iCal duration string
public static inDay ( int $daystart , int $begin , int $end ) : bool
 

Check if day falls within date range

  • param int $daystart start of day in Unix timestamp format
  • param int $begin Unix timestamp of starting date range
  • param int $end Unix timestamp of end date range
public static isAfterToday ( int $date , string $tzid = 'UTC' ) : bool
 

Is given date after today?

  • param int $date date in Unix timestamp format
  • param string $tzid PHP recognized timezone (default is UTC)
public static isBeforeToday ( int $date , string $tzid = 'UTC' ) : bool
 

Is given date before today?

  • param int $date date in Unix timestamp format
  • param string $tzid PHP recognized timezone (default is UTC)
public static isFuture ( int $date , string $tzid = 'UTC' ) : bool
 

Is given date in the future?

This routine differs from isAfterToday() in that isFuture() will
return true for date-time values later in the same day.

  • param int $date date in Unix timestamp format
  • param string $tzid PHP recognized timezone (default is UTC)
public static isPast ( int $date , string $tzid = 'UTC' ) : bool
 

Is given date in the past?

This routine differs from isBeforeToday() in that isPast() will
return true for date-time values earlier in the same day.

  • param int $date date in Unix timestamp format
  • param string $tzid PHP recognized timezone (default is UTC)
public static isToday ( int $date , string $tzid = 'UTC' ) : bool
 

Is given date today?

  • param int $date date in Unix timestamp format
  • param string $tzid PHP recognized timezone (default is UTC)
public static isTomorrow ( int $date , string $tzid = 'UTC' ) : bool
 

Is given date tomorrow?

  • param int $date date in Unix timestamp format
  • param string $tzid PHP recognized timezone (default is UTC)
public static isWeekend ( int $date ) : bool
 

Is given date fall on a weekend?

  • param int $date Unix timestamp
public static now ( string $tzid = 'UTC' ) : int
 

Return current Unix timestamp in local timezone

  • param string $tzid PHP recognized timezone
public static toiCalDate ( ? int $datetime = NULL ) : string
 

Format Unix timestamp to iCal date format

  • param int $datetime Unix timestamp
  • return string iCal date-time string
public static toiCalDateTime ( ? int $datetime = NULL ) : string
 

Format Unix timestamp to iCal date-time format

  • param int $datetime Unix timestamp
  • return string iCal date-time string
public static toLocalDateTime ( string $sqldate , string $tzid = 'UTC' ) : string
 

Convert UTC date-time to local date-time

  • param string $sqldate SQL date-time string
  • param string $tzid PHP recognized timezone (default is 'UTC')
  • return string SQL date-time string
public static toSQLDate ( int $t = 0 ) : string
 

Format Unix timestamp to SQL date

  • param int $t Unix timestamp
public static toSQLDateTime ( int $t = 0 ) : string
 

Format Unix timestamp to SQL date-time

  • param int $t Unix timestamp
public static toUnixDate ( string $datetime ) : int
 

Convert SQL date or date-time to Unix timestamp

  • param string $datetime SQL date or date-time
  • return int Unix date-time timestamp
public static toUnixDateTime ( string $datetime ) : int
 

Convert SQL date or date-time to Unix date timestamp

  • param string $datetime SQL date or date-time
  • return int Unix timestamp
public static toUTCDateTime ( string $sqldate , string $tzid = 'UTC' ) : string
 

Convert local date-time to UTC date-time

  • param string $sqldate SQL date-time string
  • param string $tzid PHP recognized timezone (default is 'UTC')
  • return string SQL date-time string
© 2022 Bruce Wells
Search Namespaces \ Classes
Configuration