Subject: | $dt->ymd_hms method (space separated) |
It'd be handy if DateTime had a $dt->ymd_hms method that returns the
'ymd' date and 'hms' time separated with a space (in contrast to
$dt->iso8601 that separates them with a 'T' char).
The date(1) command of GNU coreutils calls this format as 'RFC 3339':
http://www.gnu.org/software/coreutils/manual/coreutils.html#Options-for-date.
I wonder whether that's correct, as RFC 3339 is approximately the same
as ISO 8601 in this respect, just RFC 3339 has a somewhat obscure note
that mentions space as the separator character:
quote from RFC 3339:
NOTE: ISO 8601 defines date and time separated by "T".
Applications using this syntax may choose, for the sake of
readability, to specify a full-date and full-time separated by
(say) a space character.
If you think that the GNU coreutils guys are right, we can even call
this method $dt->rfc3339 and it'll be consistent with the GNU coreutils
date(1) command.
Subject: | DateTime-ymd_hms.diff |
Index: t/03components.t
===================================================================
--- t/03components.t (revision 4301)
+++ t/03components.t (working copy)
@@ -2,7 +2,7 @@
use strict;
-use Test::More tests => 144;
+use Test::More tests => 145;
use DateTime;
@@ -73,6 +73,8 @@
is( $d->datetime, '2001-07-05T02:12:50', '->datetime' );
is( $d->iso8601, '2001-07-05T02:12:50', '->iso8601' );
+is( $d->ymd_hms, '2001-07-05 02:12:50', '->ymd_hms' );
+
is( $d->is_leap_year, 0, '->is_leap_year' );
is( $d->era_abbr, 'AD', '->era_abbr' );
Index: lib/DateTime.pm
===================================================================
--- lib/DateTime.pm (revision 4301)
+++ lib/DateTime.pm (working copy)
@@ -815,6 +815,8 @@
sub iso8601 { join 'T', $_[0]->ymd('-'), $_[0]->hms(':') }
*datetime = \&iso8601;
+sub ymd_hms { join ' ', $_[0]->ymd('-'), $_[0]->hms(':') }
+
sub is_leap_year { $_[0]->_is_leap_year( $_[0]->year ) }
sub week
@@ -2576,6 +2578,12 @@
$dt->ymd('-') . 'T' . $dt->hms(':')
+=item * $dt->ymd_hms()
+
+This method is equivalent to:
+
+ $dt->ymd('-') . ' ' . $dt->hms(':')
+
=item * $dt->is_leap_year()
This method returns a true or false indicating whether or not the