MooseX::Types::ISO8601 - ISO8601 date and duration string type constraints and coercions for Moose
use MooseX::Types::ISO8601 qw/ ISO8601TimeDurationStr /; has duration => ( isa => ISO8601TimeDurationStr, is => 'ro', coerce => 1, ); Class->new( duration => 60 ); # 60s => PT00H01M00S Class->new( duration => DateTime::Duration->new(%args) )
This module packages several L<TypeConstraints|Moose::Util::TypeConstraints> with coercions for working with ISO8601 date strings and the DateTime suite of objects.
An ISO8601 date string. E.g.
An ISO8601 time string. E.g.
An ISO8601 combined datetime string. E.g.
An ISO8601 combined datetime string with a fully specified timezone. E.g.
The date types will coerce from:
The number is treated as a time in seconds since the unix epoch
The duration represented as a DateTime object.
Non-expanded date and time string representations.
20120113 => 2012-01-13 170500Z => 17:05:00Z 20120113T170500Z => 2012-01-13T17:05:00Z
Representations of UTC time zone (only an offset of zero is supported)
17:05:00+00:00 => 17:05:00Z 17:05:00+00 => 17:05:00Z 170500+0000 => 17:05:00Z
2012-01-13T17:05:00+00:00 => 2012-01-13T17:05:00Z 2012-01-13T17:05:00+00 => 2012-01-13T17:05:00Z 20120113T170500+0000 => 2012-01-13T17:05:00Z
Also supports non-standards mixing of expanded and non-expanded representations
2012-01-13T170500Z => 2012-01-13T17:05:00Z 20120113T17:05:00Z => 2012-01-13T17:05:00Z
An ISO8601 date duration string. E.g.
An ISO8601 time duration string. E.g.
An ISO8601 comboined date and time duration string. E.g.
The duration types will coerce from:
The number is treated as a time in seconds
The duration represented as a DateTime::Duration object.
The duration types will coerce to:
Patches are welcome.
If provided, the number of seconds in time types is represented to microsecond accuracy. A full stop character is used as the decimal seperator, which is allowed, but deprecated in preference to the comma character in ISO 8601:2004.
Probably full of them, patches are very welcome.
Specifically missing features:
No timezone support - all times are assumed UTC
No week number type
"Basic format", which lacks seperator characters, is not supported for reading or writing.
Tests are rubbish.
Tomas Doran (t0m)
The development of this code was sponsored by my employer http://www.state51.co.uk.
- Aaron Moses
Copyright (c) 2009 Tomas Doran. Some rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.