1DateTime::Format::DateMUasneirp(C3o)ntributed Perl DocumDeantteaTtiimoen::Format::DateManip(3)
2
3
4
6 DateTime::Format::DateManip - Perl DateTime extension to convert
7 Date::Manip dates and durations to DateTimes and vice versa.
8
10 use Date::Manip;
11 use DateTime::Format::DateManip;
12
13 # Date::Manip to DateTime
14 my $dm = ParseDate("January 1st, 2001");
15 my $dt = DateTime::Format::DateManip->parse_datetime($dm);
16
17 $dt->add( weeks => 1 );
18
19 # And back again
20 my $dm2 = DateTime::Format::DateManip->format_datetime($dt);
21
22 # Same thing with a duration
23 my $dm_delta = ParseDateDelta("3 years 2 days -4 hours +3mn -2 second");
24 my $dt_dur = DateTime::Format::DateManip->parse_duration($dm_delta);
25 my $dm_delta2 = DateTime::Format::DateManip->format_duration($dt_dur);
26
27 # Note that we can parse any string that is in the appropriate format
28 # there is no need to call ParseDate or ParseDateDelta first:
29 my $dt2 = DateTime::Format::DateManip->parse_datetime("In 2 hours");
30 my $dt_dur2 = DateTime::Format::DateManip->parse_duration("3 years");
31
33 DateTime::Format::DateManip is a class that knows how to convert
34 between "Date::Manip" dates and durations and "DateTime" and
35 "DateTime::Duration" objects. Recurrences are note yet supported.
36
38 Time Zones
39 "Date::Manip" can have a time zone set globally and it keeps the dates
40 it produces in the local time. In all cases we rely on the GMT offset
41 to set up the "DateTime" object. However, we try to work out what the
42 matching timezone is using the "DateTime" nomenclature and create the
43 object in the correct time zone so the date is correct if dajustments
44 to the date object pushes it over a DST change. Note that we call
45 "set_time_zone" to make the change, so the absolute time is not
46 affected by the time zone change.
47
48 However, not all "Date::Manip" time zones have reasonable mappings (for
49 example NT and CAT both appear to be obsolete). It is unlikely that a
50 user will have their time zone set to one of these items. If we are
51 unable to work out the mapping we simply use the GMT offset and do not
52 set a timezone.
53
54 When converting to a "Date::Manip" we only need to tell "Date::Manip"
55 the GMT offset and it will automatically convert to the local time zone
56 that is in effect.
57
58 Class Methods
59 · parse_datetime( $date_manip_string )
60
61 This method takes the input string and returns the corresponding
62 "DateTime" object. If "Date::Manip::ParseDate" was unable to parse
63 the input string then undef will be returned. See the note above
64 about Time Zones.
65
66 · format_datetime( $datetime_object )
67
68 This method takes the given "DateTime" object and returns a
69 corresponding "Date::Manip::ParseDate" parseable string. See the
70 note above about Time Zones.
71
72 · parse_duration( $date_manip_duration_string )
73
74 This method takes the giben duration string and returns the
75 corresponding "DateTime::Duration" object. If
76 "Date::Manip::ParseDateDelta" was unable to parse the input string
77 then undef will be returned.
78
79 · format_duration( $datetime_duration_object )
80
81 This method takes the given "DateTime::Duration" object and returns
82 a corresponding "Date::Manip::ParseDateDelta" parseable string.
83
85 Ben Bennett <fiji at limey dot net>
86
88 Copyright (c) 2003 Ben Bennett. All rights reserved. This program is
89 free software; you can redistribute it and/or modify it under the same
90 terms as Perl itself.
91
92 Portions of the code in this distribution are derived from other works.
93 Please see the CREDITS file for more details.
94
95 The full text of the license can be found in the LICENSE file included
96 with this module.
97
99 datetime@perl.org mailing list
100
101 http://datetime.perl.org/
102
103
104
105perl v5.30.1 2020-01-29 DateTime::Format::DateManip(3)