[pm-h] DateTime snippets

G. Wade Johnson gwadej at anomaly.org
Fri Sep 11 05:26:53 PDT 2015


After the discussion on Julian's time series code, I dug out some
pieces of DateTime logic I've used. These may be useful for some.

  my $LocalTZ = DateTime::TimeZone->new( time_zone => 'local' );

This variable can be passed any time DateTime needs a time zone.
Obviously, you can build other DateTime::TimeZone objects for other
time zones that you need.

  $dt->add( days => 1 );       # Move forward one day
  $dt->subtract( days => 1 );  # Move backward one day

These change the $dt object, but other than that are pretty useful. See
DateTime::Duration for other arguments you can use.

I haven't tried it, but

  $dt->truncate( to => 'day' );

Should truncate the $dt to midnight. Other values for 'to' truncate at
other spots.

HTH,
G. Wade
-- 
Results are what you wanted, consequences are what you got.
                                                 -- Michael VanDusen


More information about the Houston mailing list