[Rt-commit] rt branch, 4.0/add-dateonly-formatter, created. rt-4.0.8-211-g1a25a79

Jim Brandt jbrandt at bestpractical.com
Tue Dec 4 09:07:29 EST 2012


The branch, 4.0/add-dateonly-formatter has been created
        at  1a25a7974d07734d5df4c84c6a057a394bbedc18 (commit)

- Log -----------------------------------------------------------------
commit 1a25a7974d07734d5df4c84c6a057a394bbedc18
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Tue Dec 4 08:59:02 2012 -0500

    Add ISODateOnly formatter
    
    Add a date formatter for date only to make it available as a date
    formatting option for users.

diff --git a/lib/RT/Date.pm b/lib/RT/Date.pm
index ed094d0..651273d 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
+    'ISODateOnly',       # loc
     'W3CDTF',            # loc
     'RFC2822',           # loc
     'RFC2616',           # loc
@@ -761,6 +762,25 @@ sub ISO {
     return $res;
 }
 
+=head3 ISODateOnly
+
+A convenience method to return only the date portion of an ISO date.
+Accepts the same arguments as ISO, then ISO with Date => 1, Time => 0.
+Timezone is passed through. Seconds is ignored in ISO when Time is 0.
+
+=cut
+
+sub ISODateOnly {
+    my $self = shift;
+
+    # Set Date and Time, preserve Timezone, if passed.
+    my %args = (@_,
+                Date => 1,
+                Time => 0 );
+
+    return $self->ISO( %args );
+}
+
 =head3 W3CDTF
 
 Returns the object's date and time in W3C date time format
diff --git a/t/api/date.t b/t/api/date.t
index 728a4a2..c0e2ea9 100644
--- a/t/api/date.t
+++ b/t/api/date.t
@@ -4,7 +4,7 @@ use DateTime;
 
 use warnings;
 use strict;
-use RT::Test tests => 173;
+use RT::Test tests => 174;
 use RT::User;
 use Test::Warn;
 
@@ -103,6 +103,9 @@ my $current_user;
     is($date->ISO(Time => 0),
        '1970-01-01',
        "ISO format without time part");
+    is($date->ISODateOnly(),
+       '1970-01-01',
+       "ISO format without time part using ISODateOnly");
     is($date->W3CDTF(Time => 0),
        '1970-01-01',
        "W3CDTF format without time part");

-----------------------------------------------------------------------


More information about the Rt-commit mailing list