<<

DateUtils

Koha::DateUtils - Transitional wrappers to ease use of DateTime

DESCRIPTION

Koha has historically only used dates not datetimes and been content to handle these as strings. It also has confused formatting with actual dates this is a temporary module for wrappers to hide the complexity of switch to DateTime

dt_ftom_string

$dt = dt_from_string($date_string, [$format, $timezone ]);

Passed a date string returns a DateTime object format and timezone default to the system preferences. If the date string is empty DateTime->now is returned

output_pref

$date_string = output_pref({ dt => $dt [, dateformat => $date_format, timeformat => $time_format, dateonly => 0|1, as_due_date => 0|1 ] }); $date_string = output_pref( $dt );

Returns a string containing the time & date formatted as per the C4::Context setting, or undef if undef was provided.

This routine can either be passed a DateTime object or or a hashref. If it is passed a hashref, the expected keys are a mandatory 'dt' for the DateTime, an optional 'dateformat' to override the dateformat system preference, an optional 'timeformat' to override the TimeFormat system preference value, and an optional 'dateonly' to specify that only the formatted date string should be returned without the time.

format_sqldatetime

$string = format_sqldatetime( $string_as_returned_from_db );

a convenience routine for calling dt_from_string and formatting the result with output_pref as it is a frequent activity in scripts

flatpickr_date_format

$date_format = flatpickr_date_format( $koha_date_format );

Converts Koha's date format to Flatpickr's. E.g. 'us' returns 'm/d/Y'.

If no argument is given, the dateformat preference is assumed.

Returns undef if format is unknown.

<<