NAME
Time::Piece::Guess - Compares the passed string against common patterns and returns a format to use with Time::Piece or object
VERSION
Version 0.0.2
SYNOPSIS
use Time::Piece::Guess;
use Time::Piece;
my $string='2023-02-27T11:00:18.33';
my ($format, $ms_clean_regex) = Time::Piece::Guess->guess('2023-02-27T11:00:18');
# apply the regex if needed
if (defined( $ms_clean_regex )){
$string=~s/$ms_clean_regex//;
}
my $tp_object;
if (!defined( $format )){
print "No matching format found\n";
}else{
$tp_object = Time::Piece->strptime( '2023-02-27T11:00:18' , $format );
}
$tp_object = Time::Piece::Guess->guess_to_object('2023-02-27T11:00:18');
if (!defined( $tp_object )){
print "No matching format found\n";
}
METHODS
guess
Compares it against various patterns and returns the matching string for use with parsing that format.
If one can't be matched, undef is returned. Two values are returned. The first is the format of it and the second is a regexp to remove microseconds if needed.
This will attempt to remove microseconds as below.
my $string='2023-02-27T11:00:18.33';
my ($format, $ms_clean_regex) = Time::Piece::Guess->guess('2023-02-27T11:00:18');
# apply the regex if needed
if (defined( $ms_clean_regex )){
$string=~s/$ms_clean_regex//;
}
my $tp_object;
if (!defined( $format )){
print "No matching format found\n";
}else{
$tp_object = Time::Piece->strptime( '2023-02-27T11:00:18' , $format );
}
guess_to_object
Takes the string, calles guess on it. If it gets a hit, it then returns the Time::Piece object.
If it fails, undef is returned.
$tp_object = Time::Piece::Guess->guess_to_object('2023-02-27T11:00:18');
if (!defined( $tp_object )){
print "No matching format found\n";
}
AUTHOR
Zane C. Bowers-Hadley, <vvelox at vvelox.net>
BUGS
Please report any bugs or feature requests to bug-time-piece-guess at rt.cpan.org
, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Time-Piece-Guess. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Time::Piece::Guess
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
LICENSE AND COPYRIGHT
This software is Copyright (c) 2023 by Zane C. Bowers-Hadley.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)