WeBWorK::Utils::DateTime - contains utility subroutines for dealing with dates and times.
Usage: before($time, $now)
True if $now
is less than $time
. If $now
is not specified, the current time is used.
Usage: between($start, $end, $now)
True if $now
is greater than or equal to $start
and less than or equal to $end
. If $now
is not specified, the current time is used.
Usage: after($time, $now)
True if $now
is greater than $time
. If $now
is not specified, the current time is used.
Usage: formatDateTime($date_time, $format_string, $timezone, $locale)
Formats a $date_time
epoch into a string in the format defined by $format_string
. If $format_string
is not provided, the default WeBWorK date/time format is used. If $format_string
is a method of the $dt->locale
instance, then format_cldr
is used, and otherwise strftime
is used. The available patterns for $format_string can be found at "strftime Patterns" in DateTime. The available methods for the $dt->locale
instance are documented at DateTime::Locale::FromData. If $timezone
is given, then the formatted string that is returned is in the specified timezone. If $locale
is provided, the string returned will be in the format of that locale. If $locale
is not provided, Perl defaults to using en-US
.
If this method is used directly, then the $timezone
and $locale
should generally be set from the course environment, and the defaults set in this method not used.
This returns the default due date for a set which is two weeks from the current time with the time of day set to be $pg{timeAssignDue}
, and is in the course timezone set by $siteDefaults{timezone}
. A valid course environment object is the only required parameter.
Usage: parseDateTime($string, $display_tz)
Parses $string
into an epoch. The format of $string
must be MM/DD/YYYY at HH:MM AMPM ZONE
. There is some forgiveness for spaces, and a comma is allowed in place of "at". If $display_tz
is given, $string
is assumed to be in that timezone. Otherwise, the server's local timezone is used.
Note that this method is only used for parsing dates when set definition files are imported, and should NEVER be used for anything else ever again. If it is desired to use a human readable string to save a date then use the ISO date time format that can be reliably parsed, and do NOT use this method.
Usage: timeToSec($time)
Makes a stab at converting a time (with a possible unit) into a number of seconds.
Usage: verify_timezone($display_tz)
If $display_tz
is not a legal time zone then replace it with America/New_York and issue warning.
Note that this method is not exported, and can only be used internally by this package.