From c5826f35e794fb6222d05e2cc25cadbb3f0d4f8a Mon Sep 17 00:00:00 2001 From: Will Budic Date: Sun, 9 Nov 2025 19:55:31 +1100 Subject: [PATCH] Imp. DEFAULT_TIME_ZONE is local running node. --- system/modules/CNFDateTime.pm | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/system/modules/CNFDateTime.pm b/system/modules/CNFDateTime.pm index a0ed26f..3b32232 100644 --- a/system/modules/CNFDateTime.pm +++ b/system/modules/CNFDateTime.pm @@ -1,6 +1,6 @@ ### -# CNFDateTime objects provide conversions from script to high precision time function not inbuild into perl interpreter. -# They are lightly initilized, compared to using DateTime directly, so this is not merely a wrapper around DateTime. +# CNFDateTime objects provide conversions from script to high precision time function not inbuilt into perl interpreter. +# They are lightly initialized, compared to using DateTime directly, so this is not merely a wrapper around DateTime. # package CNFDateTime; use strict; @@ -13,11 +13,12 @@ use feature 'signatures'; use constant{ FORMAT => '%Y-%m-%d %H:%M:%S', + FORMAT_SQUASH => '%Y%m%d%H%M%S', FORMAT_Z => '%Y-%m-%d %H:%M:%S %Z', FORMAT_NANO => '%Y-%m-%d %H:%M:%S.%3N %Z', FORMAT_SCHLONG => '%A, %d %B %Y %H:%M:%S %Z', FORMAT_MEDIUM => '%d %b %Y %H:%M:%S', - DEFAULT_TIME_ZONE => 'UTC' + DEFAULT_TIME_ZONE => DateTime::TimeZone->new(name => 'local')->name() }; # CNFDateTime instances begin with now, can be epoch zero that is $NULL, or _toCNFDate() parsed, they are never new. @@ -35,6 +36,11 @@ sub now { elsif( $presume =~ /TZ|tz/){ $settings{TZ} = $r} $settings{epoch} = time if not exists $settings{epoch}; $settings{TZ} = DEFAULT_TIME_ZONE if not defined $settings{TZ}; + if(not DateTime::TimeZone->is_valid_name($settings{TZ})){ + warn "Invalid TimeZone assigned: ". $settings{TZ}; + $settings{TZ} = DEFAULT_TIME_ZONE; + warn "Reverting to system DEFAULT_TIME_ZONE: ". $settings{TZ}; + } return bless \%settings, $class } @@ -77,6 +83,9 @@ sub stamp($self){ $self -> {timestamp} = $self->datetime() -> strftime(FORMAT_NANO); return $self; } +sub toSquash($self){ + $self -> {timestamp} = $self->datetime() -> strftime(FORMAT_SQUASH) +} sub _listAvailableCountryCodes(){ require DateTime::TimeZone; -- 2.34.1