| Protocol-XMLRPC documentation | Contained in the Protocol-XMLRPC distribution. |
Protocol::XMLRPC::Value::DateTime - XML-RPC array
my $datetime = Protocol::XMLRPC::Value::DateTime->new(1234567890);
my $datetime = Protocol::XMLRPC::Value::DateTime->parse('19980717T14:08:55');
XML-RPC dateTime.iso8601
newCreates new Protocol::XMLRPC::Value::DateTime instance. Accepts unix epoch time.
parseParses dateTime.iso8601 string and creates a new Protocol::XMLRPC:::Value::Base64 instance.
typeReturns 'datetime'.
value my $datetime = Protocol::XMLRPC::Value::DateTime->new(1234567890);
# $datetime->value returns 20091302T23:31:30
Returns serialized Perl5 scalar.
to_string my $datetime = Protocol::XMLRPC::Value::DateTime->new(1234567890);
# $datetime->to_string is now '<dateTime.iso8601>20091302T23:31:30</dateTime.iso8601>'
XML-RPC datetime string representation.
Viacheslav Tykhanovskyi, vti@cpan.org.
Copyright (C) 2009, Viacheslav Tykhanovskyi.
This program is free software, you can redistribute it and/or modify it under the same terms as Perl 5.10.
| Protocol-XMLRPC documentation | Contained in the Protocol-XMLRPC distribution. |
package Protocol::XMLRPC::Value::DateTime; use strict; use warnings; use base 'Protocol::XMLRPC::Value'; require Time::Local; sub type {'datetime'} sub parse { my $class = shift; my ($datetime) = @_; my ($year, $month, $mday, $hour, $minute, $second) = ($datetime =~ m/(\d\d\d\d)(\d\d)(\d\d)T(\d\d):(\d\d):(\d\d)/); my $epoch; # Prevent crash eval { $epoch = Time::Local::timegm($second, $minute, $hour, $mday, --$month, $year); }; return if $@ || $epoch < 0; return $class->new($epoch); } sub to_string { my $self = shift; my $value = $self->value; my ($second, $minute, $hour, $mday, $month, $year, $wday) = gmtime($value); $year += 1900; $month++; #19980717T14:08:55 $value = $year . sprintf('%02d', $month) . sprintf('%02d', $mday) . 'T' . sprintf('%02d', $hour) . ':' . sprintf('%02d', $minute) . ':' . sprintf('%02d', $second); return "<dateTime.iso8601>$value</dateTime.iso8601>"; } 1; __END__