.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "DateTime::Incomplete 3pm" .TH DateTime::Incomplete 3pm "2021-01-07" "perl v5.32.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" DateTime::Incomplete \- An incomplete datetime, like January 5 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 6 \& my $dti = DateTime::Incomplete\->new( year => 2003 ); \& # 2003\-xx\-xx \& $dti\->set( month => 12 ); \& # 2003\-12\-xx \& $dt = $dti\->to_datetime( base => DateTime\->now ); \& # 2003\-12\-19T16:54:33 .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" DateTime::Incomplete is a class for representing partial dates and times. .PP These are actually encountered relatively frequently. For example, a birthday is commonly given as a month and day, without a year. .SH "ERROR HANDLING" .IX Header "ERROR HANDLING" Constructor and mutator methods (such as \f(CW\*(C`new\*(C'\fR and \f(CW\*(C`set\*(C'\fR) will die if there is an attempt to set the datetime to an invalid value. .PP Invalid values are detected by setting the appropriate fields of a \&\*(L"base\*(R" datetime object. See the \f(CW\*(C`set_base\*(C'\fR method. .PP Accessor methods (such as \f(CW\*(C`day()\*(C'\fR) will return either a value or \&\f(CW\*(C`undef\*(C'\fR, but will never die. .ie n .SH "THE ""BASE"" DATETIME" .el .SH "THE ``BASE'' DATETIME" .IX Header "THE BASE DATETIME" A \f(CW\*(C`DateTime::Incomplete\*(C'\fR object can have a \*(L"base\*(R" \f(CW\*(C`DateTime.pm\*(C'\fR object. This object is used as a default datetime in the \&\f(CW\*(C`to_datetime()\*(C'\fR method, and it also used to validate inputs to the \&\f(CW\*(C`set()\*(C'\fR method. .PP The base object must use the year/month/day system. Most calendars use this system including Gregorian (\f(CW\*(C`DateTime\*(C'\fR) and Julian. Note that this module has not been well tested with base objects from classes other than \f(CW\*(C`DateTime.pm\*(C'\fR class. .PP By default, newly created \f(CW\*(C`DateTime::Incomplete\*(C'\fR objects have no base. .SH "DATETIME-LIKE METHODS" .IX Header "DATETIME-LIKE METHODS" Most methods provided by this class are designed to emulate the behavior of \f(CW\*(C`DateTime.pm\*(C'\fR whenever possible. .IP "\(bu" 4 \&\fBnew()\fR .Sp Creates a new incomplete date: .Sp .Vb 2 \& my $dti = DateTime::Incomplete\->new( year => 2003 ); \& # 2003\-xx\-xx .Ve .Sp This class method accepts parameters for each date and time component: \&\*(L"year\*(R", \*(L"month\*(R", \*(L"day\*(R", \*(L"hour\*(R", \*(L"minute\*(R", \*(L"second\*(R", \*(L"nanosecond\*(R". Additionally, it accepts \*(L"time_zone\*(R", \*(L"locale\*(R", and \*(L"base\*(R" parameters. .Sp Any parameters not given default to \f(CW\*(C`undef\*(C'\fR. .Sp Calling the \f(CW\*(C`new()\*(C'\fR method without parameters creates a completely undefined datetime: .Sp .Vb 1 \& my $dti = DateTime::Incomplete\->new(); .Ve .IP "\(bu" 4 from_day_of_year( ... ) .Sp This constructor takes the same arguments as can be given to the \&\f(CW\*(C`new()\*(C'\fR method, except that it does not accept a \*(L"month\*(R" or \*(L"day\*(R" argument. Instead, it requires both \*(L"year\*(R" and \*(L"day_of_year\*(R". The day of year must be between 1 and 366, and 366 is only allowed for leap years. .Sp It creates a \f(CW\*(C`DateTime::Incomplete\*(C'\fR object with all date fields defined, but with the time fields (hour, minute, etc.) set to undef. .IP "\(bu" 4 from_object( object => \f(CW$object\fR, ... ) .Sp This class method can be used to construct a new \&\f(CW\*(C`DateTime::Incomplete\*(C'\fR object from any object that implements the \&\f(CW\*(C`utc_rd_values()\*(C'\fR method. All \f(CW\*(C`DateTime::Calendar\*(C'\fR modules must implement this method in order to provide cross-calendar compatibility. This method accepts a \*(L"locale\*(R" parameter. .Sp If the object passed to this method has a \f(CW\*(C`time_zone()\*(C'\fR method, that is used to set the time zone. Otherwise \s-1UTC\s0 is used. .Sp It creates a \f(CW\*(C`DateTime::Incomplete\*(C'\fR object with all fields defined. .IP "\(bu" 4 from_epoch( ... ) .Sp This class method can be used to construct a new \&\f(CW\*(C`DateTime::Incomplete\*(C'\fR object from an epoch time instead of components. Just as with the \f(CW\*(C`new()\*(C'\fR method, it accepts \*(L"time_zone\*(R" and \*(L"locale\*(R" parameters. .Sp If the epoch value is not an integer, the part after the decimal will be converted to nanoseconds. This is done in order to be compatible with \f(CW\*(C`Time::HiRes\*(C'\fR. .Sp It creates a \f(CW\*(C`DateTime::Incomplete\*(C'\fR object with all fields defined. .IP "\(bu" 4 now( ... ) .Sp This class method is equivalent to \f(CW\*(C`DateTime\->now\*(C'\fR. .Sp It creates a new \f(CW\*(C`DateTime::Incomplete\*(C'\fR object with all fields defined. .IP "\(bu" 4 today( ... ) .Sp This class method is equivalent to \f(CW\*(C`now()\*(C'\fR, but it leaves hour, minute, second and nanosecond undefined. .IP "\(bu" 4 clone .Sp Creates a new object with the same information as the object this method is called on. .ie n .SS """Get"" Methods" .el .SS "``Get'' Methods" .IX Subsection "Get Methods" .IP "\(bu" 4 year .IP "\(bu" 4 month .IP "\(bu" 4 day .IP "\(bu" 4 hour .IP "\(bu" 4 minute .IP "\(bu" 4 second .IP "\(bu" 4 nanosecond .IP "\(bu" 4 time_zone .IP "\(bu" 4 locale .Sp These methods returns the field value for the object, or \f(CW\*(C`undef\*(C'\fR. .Sp These values can also be accessed using the same alias methods available in \f(CW\*(C`DateTime.pm\*(C'\fR, such as \f(CW\*(C`mon()\*(C'\fR, \f(CW\*(C`mday()\*(C'\fR, etc. .IP "\(bu" 4 has_year .IP "\(bu" 4 has_month .IP "\(bu" 4 has_day .IP "\(bu" 4 has_hour .IP "\(bu" 4 has_minute .IP "\(bu" 4 has_second .IP "\(bu" 4 has_nanosecond .IP "\(bu" 4 has_time_zone .IP "\(bu" 4 has_locale .IP "\(bu" 4 has_date .IP "\(bu" 4 has_time .Sp Returns a boolean value indicating whether the corresponding component is defined. .Sp \&\f(CW\*(C`has_date\*(C'\fR tests for year, month, and day. .Sp \&\f(CW\*(C`has_time\*(C'\fR tests for hour, minute, and second. .IP "\(bu" 4 has .Sp .Vb 1 \& $has_date = $dti\->has( \*(Aqyear\*(Aq, \*(Aqmonth\*(Aq, \*(Aqday\*(Aq ); .Ve .Sp Returns a boolean value indicating whether all fields in the argument list are defined. .IP "\(bu" 4 defined_fields .Sp .Vb 1 \& @fields = $dti\->defined_fields; # list of field names .Ve .Sp Returns a list containing the names of the fields that are defined. .Sp The list order is: year, month, day, hour, minute, second, nanosecond, time_zone, locale. .IP "\(bu" 4 datetime, ymd, date, hms, time, iso8601, mdy, dmy .Sp These are equivalent to DateTime stringification methods with the same name, except that the undefined fields are replaced by 'xx' or 'xxxx' as appropriate. .IP "\(bu" 4 epoch .IP "\(bu" 4 hires_epoch .IP "\(bu" 4 is_dst .IP "\(bu" 4 utc_rd_values .IP "\(bu" 4 utc_rd_as_seconds .Sp .Vb 1 \& my $epoch = $dti\->epoch( base => $dt ); .Ve .Sp These methods are equivalent to the \f(CW\*(C`DateTime\*(C'\fR methods with the same name. .Sp They all accept a \*(L"base\*(R" argument to use in order to calculate the method's return values. .Sp If no \*(L"base\*(R" argument is given, then \f(CW\*(C`today\*(C'\fR is used. .IP "\(bu" 4 is_finite, is_infinite .Sp Incomplete dates are always \*(L"finite\*(R". .IP "\(bu" 4 strftime( \f(CW$format\fR, ... ) .Sp This method implements functionality similar to the \f(CW\*(C`strftime()\*(C'\fR method in C. However, if given multiple format strings, then it will return multiple scalars, one for each format string. .Sp See the \*(L"strftime Specifiers\*(R" section in the \f(CW\*(C`DateTime.pm\*(C'\fR documentation for a list of all possible format specifiers. .Sp Undefined fields are replaced by 'xx' or 'xxxx' as appropriate. .Sp The specification \f(CW%s\fR (epoch) is calculated using \f(CW\*(C`today\*(C'\fR as the base date, unless the object has a base datetime set. .PP \fIComputed Values\fR .IX Subsection "Computed Values" .PP All other accessors, such as \f(CW\*(C`day_of_week()\*(C'\fR, or \f(CW\*(C`week_year()\*(C'\fR are computed from the base values for a datetime. When these methods are called, they return the requested information if there is enough data to compute them, otherwise they return \f(CW\*(C`undef\*(C'\fR .PP \fIUnimplemented Methods\fR .IX Subsection "Unimplemented Methods" .PP The following \f(CW\*(C`DateTime.pm\*(C'\fR methods are not implemented in \&\f(CW\*(C`DateTime::Incomplete\*(C'\fR, though some of them may be implemented in future versions: .IP "\(bu" 4 add_duration .IP "\(bu" 4 add .IP "\(bu" 4 subtract_duration .IP "\(bu" 4 subtract .IP "\(bu" 4 subtract_datetime .IP "\(bu" 4 subtract_datetime_absolute .IP "\(bu" 4 delta_md .IP "\(bu" 4 delta_days .IP "\(bu" 4 delta_ms .IP "\(bu" 4 compare .IP "\(bu" 4 compare_ignore_floating .IP "\(bu" 4 DefaultLanguage .ie n .SS """Set"" Methods" .el .SS "``Set'' Methods" .IX Subsection "Set Methods" .IP "\(bu" 4 set .Sp Use this to set or undefine a datetime field: .Sp .Vb 3 \& $dti\->set( month => 12 ); \& $dti\->set( day => 24 ); \& $dti\->set( day => undef ); .Ve .Sp This method takes the same arguments as the \f(CW\*(C`set()\*(C'\fR method in \&\f(CW\*(C`DateTime.pm\*(C'\fR, but it can accept \f(CW\*(C`undef\*(C'\fR for any value. .IP "\(bu" 4 set_time_zone .Sp This method accepts either a time zone object or a string that can be passed as the \*(L"name\*(R" parameter to \f(CW\*(C`DateTime::TimeZone\->new()\*(C'\fR. .Sp Unlike with \f(CW\*(C`DateTime.pm\*(C'\fR, if the new time zone's offset is different from the previous time zone, no local time adjustment is made. .Sp You can remove time zone information by calling this method with the value \f(CW\*(C`undef\*(C'\fR. .IP "\(bu" 4 truncate( to => ... ) .Sp This method allows you to reset some of the local time components in the object to their \*(L"zero\*(R" values. The \*(L"to\*(R" parameter is used to specify which values to truncate, and it may be one of \*(L"year\*(R", \&\*(L"month\*(R", \*(L"day\*(R", \*(L"hour\*(R", \*(L"minute\*(R", or \*(L"second\*(R". For example, if \&\*(L"month\*(R" is specified, then the local day becomes 1, and the hour, minute, and second all become 0. .Sp Note that the \*(L"to\*(R" parameter \fBcannot be \*(L"week\*(R"\fR. .ie n .SH """DATETIME::INCOMPLETE"" METHODS" .el .SH "``DATETIME::INCOMPLETE'' METHODS" .IX Header "DATETIME::INCOMPLETE METHODS" \&\f(CW\*(C`DateTime::Incomplete\*(C'\fR objects also have a number of methods unique to this class. .IP "\(bu" 4 base .Sp Returns the base datetime value, or \f(CW\*(C`undef\*(C'\fR if the object has none. .IP "\(bu" 4 has_base .Sp Returns a boolean value indicating whether or not the object has a base datetime set. .IP "\(bu" 4 is_undef .Sp Returns true if the datetime is completely undefined. .IP "\(bu" 4 can_be_datetime .Sp Returns true if the datetime has enough information to be converted to a proper DateTime object. .Sp The year field must be valid, followed by a sequence of valid fields. .Sp Examples: .Sp .Vb 4 \& Can be datetime: \& 2003\-xx\-xxTxx:xx:xx \& 2003\-10\-xxTxx:xx:xx \& 2003\-10\-13Txx:xx:xx \& \& Can not be datetime: \& 2003\-10\-13Txx:xx:30 \& xxxx\-10\-13Txx:xx:30 .Ve .IP "\(bu" 4 set_base .Sp Sets the base datetime object for the \f(CW\*(C`DateTime::Incomplete\*(C'\fR object. .Sp The default value for \*(L"base\*(R" is \f(CW\*(C`undef\*(C'\fR, which means no validation is made on input. .IP "\(bu" 4 to_datetime .Sp This method takes an optional \*(L"base\*(R" parameter and returns a \&\*(L"complete\*(R" datetime. .Sp .Vb 1 \& $dt = $dti\->to_datetime( base => DateTime\->now ); \& \& $dti\->set_base( DateTime\->now ); \& $dt = $dti\->to_datetime; .Ve .Sp The resulting datetime can be either before of after the given base datetime. No adjustments are made, besides setting the missing fields. .Sp This method will use \f(CW\*(C`today\*(C'\fR if the object has no base datetime set and none is given as an argument. .Sp This method may die if it results in a datetime that doesn't actually exist, such as February 30, for example. .Sp The fields in the resulting datetime are set in this order: locale, time_zone, nanosecond, second, minute, hour, day, month, year. .IP "\(bu" 4 to_recurrence .Sp This method generates the set of all possible datetimes that fit into an incomplete datetime definition. .Sp .Vb 3 \& $dti = DateTime::Incomplete\->new( month => 12, day => 24 ); \& $dtset1 = $dti\->to_recurrence; \& # Christmas recurrence, with _seconds_ resolution \& \& $dti\->truncate( to => \*(Aqday\*(Aq ); \& $dtset2 = $dti\->to_recurrence; \& # Christmas recurrence, with days resolution (hour/min/sec = 00:00:00) .Ve .Sp Those recurrences are \f(CW\*(C`DateTime::Set\*(C'\fR objects: .Sp .Vb 1 \& $dt_next_xmas = $dti\->to_recurrence\->next( DateTime\->today ); .Ve .Sp Incomplete dates that have the year defined will generate finite sets. This kind of set can take a lot of resources (\s-1RAM\s0 and \s-1CPU\s0). The following incomplete datetime would generate the set of \fIall seconds\fR in 2003: .Sp .Vb 1 \& 2003\-xx\-xxTxx:xx:xx .Ve .Sp Recurrences are generated with up to 1 second resolution. The \&\f(CW\*(C`nanosecond\*(C'\fR value is ignored. .IP "\(bu" 4 to_spanset .Sp This method generates the set of all possible spans that fit into an incomplete datetime definition. .Sp .Vb 4 \& $dti = DateTime::Incomplete\->new( month => 12, day => 24 ); \& $dtset1 = $dti\->to_spanset; \& # Christmas recurrence, from xxxx\-12\-24T00:00:00 \& # to xxxx\-12\-25T00:00:00 .Ve .IP "\(bu" 4 start .IP "\(bu" 4 end .IP "\(bu" 4 to_span .Sp These methods view an incomplete datetime as a \*(L"time span\*(R". .Sp For example, the incomplete datetime \f(CW\*(C`2003\-xx\-xxTxx:xx:xx\*(C'\fR starts in \f(CW\*(C`2003\-01\-01T00:00:00\*(C'\fR and ends in \f(CW\*(C`2004\-01\-01T00:00:00\*(C'\fR. .Sp The \f(CW\*(C`to_span\*(C'\fR method returns a \f(CW\*(C`DateTime::Span\*(C'\fR object. .Sp An incomplete datetime without an year spans \*(L"forever\*(R". Start and end datetimes are \f(CW\*(C`undef\*(C'\fR. .IP "\(bu" 4 contains .Sp Returns a true value if the incomplete datetime range \fIcontains\fR a given datetime value. .Sp For example: .Sp .Vb 2 \& 2003\-xx\-xx contains 2003\-12\-24 \& 2003\-xx\-xx does not contain 1999\-12\-14 .Ve .IP "\(bu" 4 previous / next / closest .Sp .Vb 1 \& $dt2 = $dti\->next( $dt ); .Ve .Sp The \f(CW\*(C`next()\*(C'\fR returns the first complete date \fIafter or equal\fR to the given datetime. .Sp The \f(CW\*(C`previous()\*(C'\fR returns the first complete date \fIbefore or equal\fR to the given datetime. .Sp The \f(CW\*(C`closest()\*(C'\fR returns the closest complete date (previous or next) to the given datetime. .Sp All of these methods return \f(CW\*(C`undef\*(C'\fR if there is no matching complete datetime. .Sp If no datetime is given, these methods use the \*(L"base\*(R" datetime. .Sp Note: The definition of \f(CW\*(C`previous()\*(C'\fR and \f(CW\*(C`next()\*(C'\fR is different from the methods of the same name in the \f(CW\*(C`DateTime::Set\*(C'\fR class. .Sp The datetimes are generated with 1 nanosecond precision. The last \&\*(L"time\*(R" value of a given day is 23:59:59.999999999 (for non leapsecond days). .SH "SUPPORT" .IX Header "SUPPORT" Support for this module is provided via the datetime@perl.org email list. See http://lists.perl.org/ for more details. .SH "AUTHORS" .IX Header "AUTHORS" Flavio S. Glock .PP With Ben Bennett , Claus Farber , Dave Rolsky , Eugene Van Der Pijll , Rick Measham , and the DateTime team. .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright (c) 2003 Flavio S. Glock. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .PP The full text of the license can be found in the \s-1LICENSE\s0 file included with this module. .SH "SEE ALSO" .IX Header "SEE ALSO" datetime@perl.org mailing list .PP http://datetime.perl.org/