DateTime::TimeZone - A Raku library for working with Time Zones
use DateTime::TimeZone;
say tz-offset("-01:00"); # -3600
say timezone("Europe/Amsterdam").Int; # 3600 or 7200, depending on DST
say timezone<Europe/Amsterdam>; # DateTime::TimeZone::Zone::Europe::Amsterdam
my $dt = DateTime.now;
say to-timezone("America/Detroit", $dt);
say $dt.&to-timezone("America/Detroit");
sub frobnicate(IsTimeZone $timezone) {
say "$timezone is a valid timezone";
}
DateTime::TimeZone
is an app-facing set of friendly subroutines for working with timezones.
multi sub frobnicate(IsTimeZone $timezone) {
say "$timezone is a valid timezone";
}
multi sub frobnicate(Str:D $string) {
say "$string is *NOT* a valid timezone";
}
The IsTimeZone
subset can be used see if a given parameter is a known timezone.
Parses common offset strings (such as "01:00" and "-03:00") and returns an Int
value.
Returns a Map
of the names of the supported timezones, and the name of their associated DateTime::Timezone::Zone::
class.
Returns a DateTime::TimeZone
object representing the zone passed to it. These objects provide an .Int
call, so they may be used directly as the :timezone
parameter for a DateTime
object.
This will support any timezone listed in the Olson database.
The $datetime is used to calculate the offset depending on Daylight Savings Time rules for the given Time Zone.
If $datetime is not passed, it assumes DateTime.now()
;
Returns a DateTime::TimeZone
object representing the zone passed to it for the given epoch
value.
A shortcut for: $datetime.in-timezone(timezone($name, $datetime));
Same as the Str,DateTime
candidate, but allows being used as a method.
The dtz
script allows you to enter either an epoch value, a YYYY-MM-DD string for midnight on a date, or a YYYY-MM-DDTHH:MM:SS... string for a date/time, and an optional timezone (default: UTC). It outputs the DateTime
string for that time in that timezone.
Timothy Totten
Andrew Egeler
Elizabeth Mattijsen
Source can be located at: https://github.com/raku-community-modules/DateTime-TimeZone . Comments and Pull Requests are welcome.
Copyright 2013 - 2019 Timothy Totten
Copyright 2020 - 2022 Raku Community
This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.