logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

DateTime::Format::DateManip - Perl DateTime extension to convert Date::Manip dates and durations to

Author

       Ben Bennett <fiji at limey dot net>

Description

       DateTime::Format::DateManip is a class that knows how to convert between "Date::Manip" dates and
       durations and "DateTime" and "DateTime::Duration" objects.  Recurrences are note yet supported.

Name

       DateTime::Format::DateManip - Perl DateTime extension to convert Date::Manip dates and durations to
       DateTimes and vice versa.

See Also

datetime@perl.org mailing list

       http://datetime.perl.org/

perl v5.34.0                                       2022-08-16                   DateTime::Format::DateManip(3pm)

Synopsis

         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");

Usage

TimeZones
       "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.  However, 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 is correct if dajustments to the date object pushes it over a DST change.  Note that we call
       "set_time_zone" to make the change, so the absolute time is not affected by the time zone change.

       However, not all "Date::Manip" time zones have reasonable mappings (for example NT and CAT both appear to
       be obsolete).  It is 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.

   ClassMethods
       •   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.   See  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.  See the note above about Time Zones.

       •   parse_duration( $date_manip_duration_string )

           This method takes the giben  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.

See Also