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.
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
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.
Details
at line 51
static string
format(array $date, string $separator = '', int|string $invalidDate)
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 450
static string
mysqlToIso(string $mysql)
Converts the date/datetime from MySQL format to ISO format
at line 493
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 510
static bool
convertToDefaultDate(array $params, int $dateType, string $dateParam)
Converts the any given date to default date format.
at line 691
static bool
isDate($date)
at line 703
static bool|string
currentDBDate(null $timeStamp = NULL)
at line 713
static bool
overdue($date, null $now = NULL)
at line 745
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 772
static bool
getRange(date $startDate, date $endDate)
Find whether today's date lies in the given range
at line 803
static array
getFromTo(date $relative, $from, $to)
Get start date and end from the given relative term and unit
at line 827
static int
calculateAge(date $birthDate)
Calculate Age in Years if greater than one year else in months.
at line 891
static array
intervalAdd(string $unit, int $interval, array $date, bool $dontCareTime = FALSE)
Calculate next payment date according to provided unit & interval
at line 956
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 978
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 996
static array
datePluginToPHPFormats()
Map date plugin and actual format that is used by PHP.
at line 1030
static array
relativeToAbsolute(array $relativeTerm, int $unit)
Resolves the given relative time interval into finite time limits.
at line 1742
static int
calculateFiscalYear(int $fyDate, int $fyMonth)
Calculate current fiscal year based on the fiscal month and day.
at line 1776
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 1800
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 1828
static array
getDatePickerExtra(array $field)
Get the fields required for the 'extra' parameter when adding a datepicker.
at line 1853
static array
getDatePickerAttributes(array $field)
Get the attributes parameters required for datepicker.
at line 1881
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 1948
static string
getDateFormat(string $formatType = NULL)
Function get date format.
at line 1969
static null|string
formatDate($date, $dateType)
at line 2018
static array
getCalendarDayOfMonth()
Function to return days of the month.