GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
DateTime::Format::DateManip(3) User Contributed Perl Documentation DateTime::Format::DateManip(3)

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

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

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.

"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.

  • 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.

Ben Bennett <fiji at limey dot net>

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.

datetime@perl.org mailing list

http://datetime.perl.org/

2022-04-07 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.