]> lifelog.hopto.org Git - PerlCNF.git/commitdiff
Imp. DEFAULT_TIME_ZONE is local running node.
authorWill Budic <redacted>
Sun, 9 Nov 2025 08:55:31 +0000 (19:55 +1100)
committerWill Budic <redacted>
Sun, 9 Nov 2025 08:55:31 +0000 (19:55 +1100)
system/modules/CNFDateTime.pm

index a0ed26f65cfc065eaf5efc95445279c6bfc9adaf..3b32232f901ebc9d6bdff93a1c697ca791af1ce5 100644 (file)
@@ -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;