DateTi...teManip(3pm)
β¨ NAME β¨
DateTime::Format::DateManip β a Perl DateTime extension that converts Date::Manip dates and durations into DateTimes, and back again π (yes it goes both ways bestie, we love a two-way street)
πΈ SYNOPSIS πΈ
okay so here's the whole vibe in one go, copy it, run it, live your truth:
use Date::Manip;
use DateTime::Format::DateManip;
# Date::Manip to DateTime
my $dm = ParseDate("January 1st, 2001");
my $dt = DateTime::Format::DateManip->parse_datetime($dm);
$dt->add( weeks => 1 );
# And back again
my $dm2 = DateTime::Format::DateManip->format_datetime($dt);
# Same thing with a duration
my $dm_delta = ParseDateDelta("3 years 2 days -4 hours +3mn -2 second");
my $dt_dur = DateTime::Format::DateManip->parse_duration($dm_delta);
my $dm_delta2 = DateTime::Format::DateManip->format_duration($dt_dur);
# Note that we can parse any string that is in the appropriate format
# there is no need to call ParseDate or ParseDateDelta first:
my $dt2 = DateTime::Format::DateManip->parse_datetime("In 2 hours");
my $dt_dur2 = DateTime::Format::DateManip->parse_duration("3 years");
π DESCRIPTION π
So DateTime::Format::DateManip is a class that knows how to convert between Date::Manip dates and durations and DateTime / DateTime::Duration objects. It's giving translator, it's giving bilingual icon. Recurrences are not yet supported though β sorry babe, that part isn't here yet π
π¦ USAGE π¦
π Time Zones π
Date::Manip can have a time zone set globally, and it keeps the dates it produces in the local time. In all cases we rely on the GMT offset</> to set up the DateTime object. BUT β and this is the cute part β we try to work out what the matching timezone is using the DateTime nomenclature and create the object in the correct time zone, so the date stays correct even if adjustments to the date object push it over a DST change. π°οΈβ¨
Heads up bestie: we call set_time_zone to make the change, so the absolute time is not affected by the time zone change. No cap.
However!! Not all Date::Manip time zones have reasonable mappings β for example NT and CAT both appear to be obsolete. π It's unlikely that a user will have their time zone set to one of these items. If we are unable to work out the mapping we simply use the GMT offset and do not set a timezone.
When converting to a Date::Manip we only need to tell Date::Manip the GMT offset and it will automatically convert to the local time zone that is in effect. Easy. Slay. π
β Class Methods β
parse_datetime( $date_manip_string )β This method takes the input string and returns the correspondingDateTimeobject. IfDate::Manip::ParseDatewas unable to parse the input string then undef will be returned. Peep the note above about Time Zones. π«Άformat_datetime( $datetime_object )β This method takes the givenDateTimeobject and returns a correspondingDate::Manip::ParseDateparseable string. Again, see the note above about Time Zones. πparse_duration( $date_manip_duration_string )β This method takes the given duration string and returns the correspondingDateTime::Durationobject. IfDate::Manip::ParseDateDeltawas unable to parse the input string then undef will be returned. πformat_duration( $datetime_duration_object )β This method takes the givenDateTime::Durationobject and returns a correspondingDate::Manip::ParseDateDeltaparseable string. π
π AUTHOR π
Ben Bennett <fiji at limey dot net> β the icon, the legend, the moment π
π COPYRIGHT π
Copyright (c) 2003 Ben Bennett. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Portions of the code in this distribution are derived from other works. Please see the CREDITS file for more details. π
The full text of the license can be found in the LICENSE file included with this module.
π¦ SEE ALSO π¦
datetime@perl.orgmailing list π¬- http://datetime.perl.org/ π
okay that's the whole page bestie, go forth and convert dates π
This is from perl v5.34.0, dated 2022-08-16, and it lives in the User Contributed Perl Documentation section under the name DateTi...teManip(3pm). Mwah. π β¨
π¦ where this page comes from
- debian bookworm: libdatetime-format-datemanip-perl 0.04-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libdatetime-format-datemanip-perl 0.04-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libdatetime-format-datemanip-perl 0.04-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libdatetime-format-datemanip-perl 0.04-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libdatetime-format-datemanip-perl 0.04-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms