Time::Moment::Role::Strptime - strptime constructor for Time::Moment
use Time::Moment; use Role::Tiny (); my $class = Role::Tiny->create_class_with_roles('Time::Moment', 'Time::Moment::Role::Strptime'); my $moment = $class->strptime('2019-06-01', '%Y-%m-%d');
This role composes the "strptime" method, which parses the input string according to a strptime(3) format, and constructs a Time::Moment object.
By default the returned Time::Moment object is in UTC (possibly adjusted by a parsed offset); to interpret the parsed time in another time zone, you can use Time::Moment::Role::TimeZone:
use Time::Moment; use Role::Tiny (); my $class = Role::Tiny->create_class_with_roles('Time::Moment', 'Time::Moment::Role::Strptime', 'Time::Moment::Role::TimeZone'); my $moment = $class->strptime($input, $format)->with_system_offset_same_local; use DateTime::TimeZone::Olson 'olson_tz'; my $tz = olson_tz('America/Los_Angeles'); my $moment = $class->strptime($input, $format)->with_time_zone_offset_same_local($tz);
my $moment = $class->strptime($input, $format);
Parses the input string according to the strptime(3) format, and returns a Time::Moment object in UTC. Throws an exception on parsing or out-of-bounds errors.
Currently, Time::Piece is used to implement strptime portably, but this is considered an implementation detail.
strptime
Report any issues on the public bugtracker.
Dan Book <dbook@cpan.org>
This software is Copyright (c) 2019 by Dan Book.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
Time::Moment
To install Time::Moment::Role::Strptime, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Time::Moment::Role::Strptime
CPAN shell
perl -MCPAN -e shell install Time::Moment::Role::Strptime
For more information on module installation, please visit the detailed CPAN module installation guide.