CRM_Utils_Date
class CRM_Utils_Date
Date utilties
Methods
Format a date by padding it with leading '0'.
Return abbreviated weekday names according to the locale.
Return full weekday names according to the locale.
Return abbreviated month names according to the locale.
Return full month names according to the locale.
No description
Create a date and time string in a provided format.
Wrapper for customFormat that takes a timestamp
Converts the date/datetime from MySQL format to ISO format
Converts the date/datetime from ISO format to MySQL format Note that until CRM-14986/ 4.4.7 this was required whenever the pattern $dao->find(TRUE): $dao->save(); was used to update an object with a date field was used. The DAO now checks for a '-' in date field strings & runs this function if the - appears - meaning it is likely redundant in the form & BAO layers
Converts the any given date to default date format.
No description
Translate a TTL to a concrete expiration time.
No description
No description
Get customized today.
Find whether today's date lies in the given range
Get start date and end from the given relative term and unit
Calculate Age in Years if greater than one year else in months.
Calculate next payment date according to provided unit & interval
Get the smarty view presentation mapping for the given format.
Pick the smarty format from settings that best matches the time string we have.
Map date plugin and actual format that is used by PHP.
Resolves the given relative time interval into finite time limits.
Calculate current fiscal year based on the fiscal month and day.
Function to process date, convert to mysql format
Add the metadata about a date field to the field.
Get the fields required for the 'extra' parameter when adding a datepicker.
Get the attributes parameters required for datepicker.
Function to convert mysql to date plugin format.
Function get date format.
No description
Function to return days of the month.
Convert a relative date format to an api field.
Print out a date object in specified format in local timezone
Details
at line 51
static string
format(array $date, string $separator = '', int|string $invalidDate = 0)
Format a date by padding it with leading '0'.
at line 178
static array
getAbbrWeekdayNames()
Return abbreviated weekday names according to the locale.
Array will be in localized order according to 'weekBegins' setting, but array keys will always match to: 0 => Sun 1 => Mon etc.
at line 207
static array
getFullWeekdayNames()
Return full weekday names according to the locale.
Array will be in localized order according to 'weekBegins' setting, but array keys will always match to: 0 => Sunday 1 => Monday etc.
at line 232
static array
getAbbrMonthNames(bool $month = FALSE)
Return abbreviated month names according to the locale.
at line 255
static array
getFullMonthNames()
Return full month names according to the locale.
at line 273
static int
unixTime($string)
at line 316
static string
customFormat(string $dateString, string $format = NULL, array $dateParts = NULL)
Create a date and time string in a provided format.
%b - abbreviated month name ('Jan'..'Dec') %B - full month name ('January'..'December') %d - day of the month as a decimal number, 0-padded ('01'..'31') %e - day of the month as a decimal number, blank-padded (' 1'..'31') %E - day of the month as a decimal number ('1'..'31') %f - English ordinal suffix for the day of the month ('st', 'nd', 'rd', 'th') %H - hour in 24-hour format, 0-padded ('00'..'23') %I - hour in 12-hour format, 0-padded ('01'..'12') %k - hour in 24-hour format, blank-padded (' 0'..'23') %l - hour in 12-hour format, blank-padded (' 1'..'12') %m - month as a decimal number, 0-padded ('01'..'12') %M - minute, 0-padded ('00'..'60') %p - lowercase ante/post meridiem ('am', 'pm') %P - uppercase ante/post meridiem ('AM', 'PM') %Y - year as a decimal number including the century ('2005')
at line 454
static string
customFormatTs(int $timestamp, string $format = NULL, array $dateParts = NULL)
Wrapper for customFormat that takes a timestamp
at line 467
static string
mysqlToIso(string $mysql)
Converts the date/datetime from MySQL format to ISO format
at line 510
static string
isoToMysql(string $iso)
Converts the date/datetime from ISO format to MySQL format Note that until CRM-14986/ 4.4.7 this was required whenever the pattern $dao->find(TRUE): $dao->save(); was used to update an object with a date field was used. The DAO now checks for a '-' in date field strings & runs this function if the - appears - meaning it is likely redundant in the form & BAO layers
at line 527
static bool
convertToDefaultDate(array $params, int $dateType, string $dateParam)
Converts the any given date to default date format.
at line 708
static bool
isDate($date)
at line 725
static int
convertCacheTtlToExpires(NULL|int|DateInterval $ttl, int $default)
Translate a TTL to a concrete expiration time.
at line 751
static int
convertCacheTtl(NULL|int|DateInterval $ttl, int $default)
Normalize a TTL.
at line 771
static bool|string
currentDBDate(null $timeStamp = NULL)
at line 781
static bool
overdue($date, null $now = NULL)
at line 813
static string
getToday(array $dayParams = NULL, string $format = "Y-m-d")
Get customized today.
This function is used for getting customized today. To get actuall today pass 'dayParams' as null. or else pass the day, month, year values as array values Example: $dayParams = array( 'day' => '25', 'month' => '10', 'year' => '2007' );
at line 840
static bool
getRange(date $startDate, date $endDate)
Find whether today's date lies in the given range
at line 873
static array
getFromTo(string $relative, string $from, string $to, string $fromTime = NULL, string $toTime = '235959')
Get start date and end from the given relative term and unit
at line 903
static int
calculateAge(date $birthDate)
Calculate Age in Years if greater than one year else in months.
at line 967
static array
intervalAdd(string $unit, int $interval, array $date, bool $dontCareTime = FALSE)
Calculate next payment date according to provided unit & interval
at line 1032
static string|null
getDateFieldViewFormat($format)
Get the smarty view presentation mapping for the given format.
Historically it was decided that where the view format is 'dd/mm/yy' or 'mm/dd/yy' they should be rendered using a longer date format. This is likely as much to do with the earlier date widget being unable to handle some formats as usablity. However, we continue to respect this.
at line 1054
static mixed
pickBestSmartyFormat($format)
Pick the smarty format from settings that best matches the time string we have.
For view purposes we historically use the setting that most closely matches the data in the format from our settings, as opposed to the setting configured for the field.
at line 1072
static array
datePluginToPHPFormats()
Map date plugin and actual format that is used by PHP.
at line 1106
static array
relativeToAbsolute(string $relativeTerm, int $unit)
Resolves the given relative time interval into finite time limits.
at line 1892
static int
calculateFiscalYear(int $fyDate, int $fyMonth)
Calculate current fiscal year based on the fiscal month and day.
at line 1926
static string
processDate(string $date, string $time = NULL, bool|string $returnNullString = FALSE, string $format = 'YmdHis')
Function to process date, convert to mysql format
at line 1950
static array
addDateMetadataToField(array $fieldMetaData, array $field)
Add the metadata about a date field to the field.
This metadata will work with the call $form->add('datepicker', ...
at line 1977
static array
getDatePickerExtra(array $field)
Get the fields required for the 'extra' parameter when adding a datepicker.
at line 2002
static array
getDatePickerAttributes(array $field)
Get the attributes parameters required for datepicker.
at line 2030
static array
setDateDefaults(string $mysqlDate = NULL, null $formatType = NULL, null $format = NULL, null $timeFormat = NULL)
Function to convert mysql to date plugin format.
at line 2097
static string
getDateFormat(string $formatType = NULL)
Function get date format.
at line 2118
static null|string
formatDate($date, $dateType)
at line 2167
static array
getCalendarDayOfMonth()
Function to return days of the month.
at line 2187
static
convertFormDateToApiFormat(array $params, string $dateField, bool $isDatePicker = TRUE)
Convert a relative date format to an api field.
at line 2221
static string
convertDateToLocalTime(DateTimeObject $dateObject, string $format = 'YmdHis')
Print out a date object in specified format in local timezone