[Rt-commit] rt branch, 4.4/iso-tz-date-formatter, created. rt-4.4.4-6-g34d191357
Blaine Motsinger
blaine at bestpractical.com
Tue Mar 19 19:39:36 EDT 2019
The branch, 4.4/iso-tz-date-formatter has been created
at 34d19135720ec877374273c8daa4429112473048 (commit)
- Log -----------------------------------------------------------------
commit 34d19135720ec877374273c8daa4429112473048
Author: Blaine Motsinger <blaine at bestpractical.com>
Date: Tue Mar 19 18:35:48 2019 -0500
Added new ISOTZ date formatter
This new formatter returns the object's date in ISO format with
TZ name abbreviation.
diff --git a/lib/RT/Date.pm b/lib/RT/Date.pm
index e76ae707d..a0be0b202 100644
--- a/lib/RT/Date.pm
+++ b/lib/RT/Date.pm
@@ -115,6 +115,7 @@ our @DAYS_OF_WEEK = (
our @FORMATTERS = (
'DefaultFormat', # loc
'ISO', # loc
+ 'ISOTZ', # loc
'W3CDTF', # loc
'RFC2822', # loc
'RFC2616', # loc
@@ -877,6 +878,42 @@ sub ISO {
return $res;
}
+=head3 ISOTZ
+
+Returns the object's date in ISO format with TZ name abbreviation
+C<YYYY-MM-DD mm:hh TZ>. ISOTZ is locale-independent and is nearly
+identical to ISO, but with appended TZ name and without seconds.
+
+Supports arguments: C<Timezone>, C<Date>, and C<Time>.
+See L</Output formatters> for description of arguments.
+
+=cut
+
+sub ISOTZ {
+ my $self = shift;
+ my %args = ( Date => 1,
+ Time => 1,
+ Timezone => '',
+ @_,
+ );
+ # 0 1 2 3 4 5 6 7 8 9
+ my ($sec,$min,$hour,$mday,$mon,$year,$wday,$ydaym,$isdst,$offset) =
+ $self->Localtime($args{'Timezone'});
+
+ # the month needs incrementing, as gmtime returns 0-11
+ $mon++;
+
+ my $dt = $self->DateTimeObj(%args);
+
+ my $res = '';
+ $res .= sprintf('%04d-%02d-%02d', $year, $mon, $mday) if $args{'Date'};
+ $res .= sprintf(' %02d:%02d', $hour, $min) if $args{'Time'};
+ $res .= sprintf(' %03s', $dt->time_zone_short_name());
+ $res =~ s/^\s+//;
+
+ return $res;
+}
+
=head3 W3CDTF
Returns the object's date and time in W3C date time format
-----------------------------------------------------------------------
More information about the rt-commit
mailing list