include/SugarDateTime.php
\SugarDateTime
Sugar DateTime container Extends regular PHP DateTime with useful services
- Parent(s)
 - \DateTime
 - Api
 
Properties

                 $data_init= 'array(
        "tm_hour" => 0,
        "tm_min" => 0,
        "tm_sec" => 0,
    )'
                array(
        "tm_hour" => 0,
        "tm_min" => 0,
        "tm_sec" => 0,
    )Details- Type
 - n/a
 

                 $formats= 'array(
		"sec" => "s",
		"min" => "i",
		"hour" => "G",
		"zhour" => "H",
		"day" => "j",
		"zday" => "d",
		"days_in_month" => "t",
		"day_of_week" => "w",
		"day_of_year" => "z",
		"week" => "W",
		"month" => "n",
		"zmonth" => "m",
		"year" => "Y",
		"am_pm" => "A",
		"hour_12" => "g",
	)'
                
array(
		"sec" => "s",
		"min" => "i",
		"hour" => "G",
		"zhour" => "H",
		"day" => "j",
		"zday" => "d",
		"days_in_month" => "t",
		"day_of_week" => "w",
		"day_of_year" => "z",
		"week" => "W",
		"month" => "n",
		"zmonth" => "m",
		"year" => "Y",
		"am_pm" => "A",
		"hour_12" => "g",
	)Details- Type
 - n/a
 

array
                 $parts_match= 'array(
            'Y' => 'tm_year',
            'm' => 'tm_mon',
            'n' => 'tm_mon',
            'd' => 'tm_mday',
            'H' => 'tm_hour',
            'h' => 'tm_hour',
            'i' => 'tm_min',
            's' => 'tm_sec',
    )'
                Match between tm_ parts and date() format strings
array(
            'Y' => 'tm_year',
            'm' => 'tm_mon',
            'n' => 'tm_mon',
            'd' => 'tm_mday',
            'H' => 'tm_hour',
            'h' => 'tm_hour',
            'i' => 'tm_min',
            's' => 'tm_sec',
    )Details- Type
 - array
 

bool
                 $use_php_parser= 'true'
                For testing - if we allowed to use PHP date parse
trueDetails- Type
 - bool
 

bool
                 $use_strptime= 'true'
                For testing - if we allowed to use strptime()
trueDetails- Type
 - bool
 

                 $var_gets= 'array(
		"24_hour" => "hour",
		"day_of_week" => "day_of_week_long",
		"day_of_week_short" => "day_of_week_short",
		"month_name" => "month_long",
		"hour" => "hour_12",
	)'
                
array(
		"24_hour" => "hour",
		"day_of_week" => "day_of_week_long",
		"day_of_week_short" => "day_of_week_short",
		"month_name" => "month_long",
		"hour" => "hour_12",
	)Details- Type
 - n/a
 
Methods

__call(
          string $name, array $args
          )
        
        :
          mixedImplement some get_ methods that fetch variables
| Name | Type | Description | 
|---|---|---|
| $name | string | |
| $args | array | 
| Type | Description | 
|---|---|
| mixed | 

__get(
          string $var
          )
        
        :
          mixedFetch property of the date by name
| Name | Type | Description | 
|---|---|---|
| $var | string | Property name  | 
| Type | Description | 
|---|---|
| mixed | 

__toString(
          
          )
        
        :
          stringConvert date to string - 'r' format, like: Thu, 21 Dec 2000 16:01:07 +0200
| Type | Description | 
|---|---|
| string | 

asDb(
          bool $tz
              =
              true
          )
        
        :
          stringPrint datetime in standard DB format
Set $tz parameter to false if you are sure that the date is in UTC.
| Name | Type | Description | 
|---|---|---|
| $tz | bool | do conversion to UTC  | 
| Type | Description | 
|---|---|
| string | 

asDbDate(
          bool $tz
              =
              true
          )
        
        :
          stringPrint date in standard DB format
Set $tz parameter to false if you are sure that the date is in UTC.
| Name | Type | Description | 
|---|---|---|
| $tz | bool | do conversion to UTC  | 
| Type | Description | 
|---|---|
| string | 

createFromFormat(
          string $format, string $time, \DateTimeZone $timezone
              =
              null
          )
        
        :
          \SugarDateTimeCopy of DateTime::createFromFormat
Needed to return right type of the object
| Name | Type | Description | 
|---|---|---|
| $format | string | Format like in date()  | 
| $time | string | Time to parse  | 
| $timezone | \DateTimeZone | 
| Type | Description | 
|---|---|
| \SugarDateTime | 
- See
 - \DateTime::createFromFormat
 

get(
          string $expression
          )
        
        :
          \SugarDateTimeGet new date, modified by date expression
| Name | Type | Description | 
|---|---|---|
| $expression | string | 
| Type | Description | 
|---|---|
| \SugarDateTime | 
- Example
 - $yesterday = $today->get("yesterday");
 

getHashList(
          string $view, \SugarDateTime $start_time, \SugarDateTime $end_time
          )
        
        :
          arrayCreate a list of time slots for calendar view Times must be in user TZ
| Name | Type | Description | 
|---|---|---|
| $view | string | Which view we are using - day, week, month  | 
| $start_time | \SugarDateTime | Start time  | 
| $end_time | \SugarDateTime | End time  | 
| Type | Description | 
|---|---|
| array | 

get_date_str(
          
          )
        
        :
          stringGet query string for the date, year=%d&month=%d&day=%d&hour=%d
| Type | Description | 
|---|---|
| string | 

get_datetime_by_index_today(
          int $hour_index
          )
        
        :
          \SugarDateTimeGet specific hour of today
| Name | Type | Description | 
|---|---|---|
| $hour_index | int | 
| Type | Description | 
|---|---|
| \SugarDateTime | 

get_day_begin(
          int $day
              =
              null, int $month
              =
              null, int $year
              =
              null
          )
        
        :
          \SugarDateTimeGet the beginning of the given day
| Name | Type | Description | 
|---|---|---|
| $day | int | Day, starting with 1, default is current  | 
| $month | int | Month, starting with 1, default is current  | 
| $year | int | Year, default is current  | 
| Type | Description | 
|---|---|
| \SugarDateTime | 

get_day_by_index_this_month(
          int $day_index
          )
        
        :
          \SugarDateTimeGet the beginning of i's day of the month
| Name | Type | Description | 
|---|---|---|
| $day_index | int | 0 is the first day of the month (sic!)  | 
| Type | Description | 
|---|---|
| \SugarDateTime | 

get_day_by_index_this_week(
          int $day_index
          )
        
        :
          \SugarDateTimeGet the beginning of i's day of the week
| Name | Type | Description | 
|---|---|---|
| $day_index | int | Day, 0 is Sunday, 1 is Monday, etc.  | 
| Type | Description | 
|---|---|
| \SugarDateTime | 

get_day_by_index_this_year(
          int $month_index
          )
        
        :
          \SugarDateTimeGet the beginning of the last day of i's the month
| Name | Type | Description | 
|---|---|---|
| $month_index | int | Month, January is 0  | 
| Type | Description | 
|---|---|
| \SugarDateTime | 
- Deprecated
 - FIXME: no idea why this function exists and what's the use of it
 

get_day_end(
          int $day
              =
              null, int $month
              =
              null, int $year
              =
              null
          )
        
        :
          \SugarDateTimeGet the last second of the given day
| Name | Type | Description | 
|---|---|---|
| $day | int | Day, starting with 1, default is current  | 
| $month | int | Month, starting with 1, default is current  | 
| $year | int | Year, default is current  | 
| Type | Description | 
|---|---|
| \SugarDateTime | 

get_day_end_time(
          
          )
        
        :
          \SugarDateTimeGet the last second of the current day
| Type | Description | 
|---|---|
| \SugarDateTime | 

get_hour_end_time(
          
          )
        
        :
          \SugarDateTimeGet the last second of current hour
| Type | Description | 
|---|---|
| \SugarDateTime | 

get_year_begin(
          int $year
          )
        
        :
          \SugarDateTimeGet the beginning of the first day of the year
| Name | Type | Description | 
|---|---|---|
| $year | int | 
| Type | Description | 
|---|---|
| \SugarDateTime | 

modify(
           $modify
          )
        
        :
          \SugarDateTime(non-PHPdoc)
| Name | Type | Description | 
|---|---|---|
| $modify | 
| Type | Description | 
|---|---|
| \SugarDateTime | 
- See
 - \DateTime::modify()
 

parse_utc_date_time(
          string $str
          )
        
        :
          \SugarDateTimeCreate from ISO 8601 datetime
| Name | Type | Description | 
|---|---|---|
| $str | string | 
| Type | Description | 
|---|---|
| \SugarDateTime | 

setDate(
           $year,  $month,  $day
          )
        
        :
          \SugarDateTime(non-PHPdoc)
| Name | Type | Description | 
|---|---|---|
| $year | ||
| $month | ||
| $day | 
| Type | Description | 
|---|---|
| \SugarDateTime | 
- See
 - \DateTime::setDate()
 

setTime(
           $hour,  $minute, int $sec
              =
              0
          )
        
        :
          \SugarDateTime(non-PHPdoc)
| Name | Type | Description | 
|---|---|---|
| $hour | ||
| $minute | ||
| $sec | int | 
| Type | Description | 
|---|---|
| \SugarDateTime | 
- See
 - \DateTime::setTime()
 

setTimezone(
          \DateTimeZone $timezone
          )
        
        :
          \SugarDateTime(non-PHPdoc)
| Name | Type | Description | 
|---|---|---|
| $timezone | \DateTimeZone | 
| Type | Description | 
|---|---|
| \SugarDateTime | 
- See
 - \DateTime::setTimezone()