DateTi...teManip(3pm)

πŸ“¦
version 0.04 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ 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 corresponding DateTime object. If Date::Manip::ParseDate was 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 given DateTime object and returns a corresponding Date::Manip::ParseDate parseable 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 corresponding DateTime::Duration object. If Date::Manip::ParseDateDelta was unable to parse the input string then undef will be returned. 😭
  • format_duration( $datetime_duration_object ) β€” This method takes the given DateTime::Duration object and returns a corresponding Date::Manip::ParseDateDelta parseable string. πŸ‘‘

πŸ‘‘ AUTHOR πŸ‘‘

Ben Bennett <fiji at limey dot net> β€” the icon, the legend, the moment πŸ’–


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 πŸ¦‹


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