From f38513392d69317a734f34afc0b71b365b2ced24 Mon Sep 17 00:00:00 2001 From: Tom Browder Date: Wed, 21 Feb 2024 18:04:50 -0600 Subject: [PATCH 1/3] test before new version release --- Changes | 4 ++++ META6.json | 2 +- README.md | 6 ++++-- docs/README.rakudoc | 6 ++++-- lib/DateTime/US.rakumod | 17 ++++++----------- t/3-local-utc.t | 2 +- t/7-doc-example.t | 20 ++++++++++++++++++++ 7 files changed, 40 insertions(+), 17 deletions(-) create mode 100644 t/7-doc-example.t diff --git a/Changes b/Changes index eb2842c..5df5c52 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,10 @@ Revision history for DateTime-US {{$NEXT}} + - Use LocalTime to add correct suffix to local time output + - Correct README example + - Correct errors in use of LocalTime + - Remove some old comments in code 0.1.3 2024-02-11T11:38:40-06:00 - Remove all reduntant DST test data into a separate file diff --git a/META6.json b/META6.json index cbbb36f..cef3022 100644 --- a/META6.json +++ b/META6.json @@ -6,8 +6,8 @@ "build-depends": [ ], "depends": [ - "Date::Utils", "UUID::V4", + "LocalTime", "Timezones::US" ], "description": "Provides time zone and Daylight Saving Time (DST) infomation for US states and territories", diff --git a/README.md b/README.md index b44c790..7cf6b90 100644 --- a/README.md +++ b/README.md @@ -24,9 +24,11 @@ Module **DateTime::US** provides a class with methods used to help Raku programs The main use case that motivated the module is to convert time in UTC to local time for creating calendars and almanacs. For example, local Sunrise is given in UTC and will normally be shown on a calendar in local time: - my $tz = DateTime.new: :timezone('CST'); - my $sunriseZ = DateTime.new: "2022-10-03T05:45:00Z"; + my $tz = DateTime::US.new: :timezone; + my $sunriseZ = DateTime.new: "2024-02-21T12:23:00Z"; + say $sunriseZ; # OUTPUT: «2024-02-21T12:23:00Z␤» my $localtime = $tz.to-localtime :utc($sunriseZ); + say $localtime; # OUTPUT: «2024-02-21T06:23:00 CST␤» Class methods ------------- diff --git a/docs/README.rakudoc b/docs/README.rakudoc index 29a025a..cfb221b 100644 --- a/docs/README.rakudoc +++ b/docs/README.rakudoc @@ -32,9 +32,11 @@ time for creating calendars and almanacs. For example, local Sunrise is given in UTC and will normally be shown on a calendar in local time: =begin code -my $tz = DateTime.new: :timezone('CST'); -my $sunriseZ = DateTime.new: "2022-10-03T05:45:00Z"; +my $tz = DateTime::US.new: :timezone; +my $sunriseZ = DateTime.new: "2024-02-21T12:23:00Z"; +say $sunriseZ; # OUTPUT: «2024-02-21T12:23:00Z␤» my $localtime = $tz.to-localtime :utc($sunriseZ); +say $localtime; # OUTPUT: «2024-02-21T06:23:00 CST␤» =end code =head2 Class methods diff --git a/lib/DateTime/US.rakumod b/lib/DateTime/US.rakumod index 07ee972..6d96256 100644 --- a/lib/DateTime/US.rakumod +++ b/lib/DateTime/US.rakumod @@ -1,22 +1,13 @@ unit class DateTime::US; use Timezones::US; -#use Date::Utils; +use LocalTime; has $.timezone is required; has $.name; has $.utc-offset; has $.dst-exceptions; -=begin comment -#| Formatter for local time -our $lt-format = sub ($self) is export { - sprintf "%04d-%02d-%02dT%02d:%02d:%02d", - .year, .month, .day, .hour, .minute, .second - given $self -} -=end comment - submethod TWEAK { # only certain names are recognized # also translate 'Xdt' to 'Xst' @@ -40,7 +31,11 @@ multi method to-localtime(DateTime :$utc! --> DateTime) { $utc-offset += 1; # make time 1 hour later $lt = $utc + Duration.new($utc-offset * SEC-PER-HOUR); } - $lt + # Use correct localtime as suffix + my $lt2 = LocalTime.new: :year($lt.year), :month($lt.month), :day($lt.day), + :hour($lt.hour), :minute($lt.minute), + :second($lt.second), :tz-abbrev; + $lt2.dt } multi method to-utc(DateTime :$localtime! --> DateTime) { diff --git a/t/3-local-utc.t b/t/3-local-utc.t index cb78622..f527010 100644 --- a/t/3-local-utc.t +++ b/t/3-local-utc.t @@ -31,6 +31,7 @@ is $ut1.hour, 9; is $ut2.hour, 8; is $ut3.hour, 9; + # and the reverse my $ut4 = DateTime.new: :year(2000), :month(1), :day(25), :10hour; # no dst my $ut5 = DateTime.new: :year(2000), :month(3), :day(25), :10hour; # dst @@ -48,4 +49,3 @@ is $lt4.hour, 4; is $lt5.hour, 5; is $lt6.hour, 4; - diff --git a/t/7-doc-example.t b/t/7-doc-example.t new file mode 100644 index 0000000..e9c3bb9 --- /dev/null +++ b/t/7-doc-example.t @@ -0,0 +1,20 @@ +use Test; + +use DateTime::US; +use LocalTime; + +my $tz = DateTime::US.new: :timezone; +my $sunriseZ = DateTime.new: "2024-02-21T12:23:00Z"; +say $sunriseZ; # 2024-02-21T12:23:00Z +my $localtime = $tz.to-localtime :utc($sunriseZ); +say $localtime; # 2024-02-21T06:23:00 CST + +is $localtime.year, 2024; +is $localtime.month, 2; +is $localtime.day, 21; +is $localtime.hour, 6; +is $localtime.minute, 23; +is $localtime.second, 0; + +done-testing; + From b656becf4fdc06a22166516bc23265b6916a54d2 Mon Sep 17 00:00:00 2001 From: Tom Browder Date: Wed, 21 Feb 2024 18:05:54 -0600 Subject: [PATCH 2/3] test before new version release --- Changes | 1 + 1 file changed, 1 insertion(+) diff --git a/Changes b/Changes index 5df5c52..8099b02 100644 --- a/Changes +++ b/Changes @@ -5,6 +5,7 @@ Revision history for DateTime-US - Correct README example - Correct errors in use of LocalTime - Remove some old comments in code + - Add test for README example 0.1.3 2024-02-11T11:38:40-06:00 - Remove all reduntant DST test data into a separate file From 3093e30f8f0eb018c25731383efc640c156cf225 Mon Sep 17 00:00:00 2001 From: Tom Browder Date: Wed, 21 Feb 2024 18:24:38 -0600 Subject: [PATCH 3/3] add missing dep --- META6.json | 1 + 1 file changed, 1 insertion(+) diff --git a/META6.json b/META6.json index cef3022..fb4aa42 100644 --- a/META6.json +++ b/META6.json @@ -8,6 +8,7 @@ "depends": [ "UUID::V4", "LocalTime", + "Date::Utils", "Timezones::US" ], "description": "Provides time zone and Daylight Saving Time (DST) infomation for US states and territories",