DateTime::Incomplete(3pm) User Contributed Perl Documentation DateTime::Incomplete(3pm)

DateTime::Incomplete - An incomplete datetime, like January 5

  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

DateTime::Incomplete is a class for representing partial dates and times.

These are actually encountered relatively frequently. For example, a birthday is commonly given as a month and day, without a year.

Constructor and mutator methods (such as "new" and "set") will die if there is an attempt to set the datetime to an invalid value.

Invalid values are detected by setting the appropriate fields of a "base" datetime object. See the "set_base" method.

Accessor methods (such as day()) will return either a value or "undef", but will never die.

A "DateTime::Incomplete" object can have a "base" "DateTime.pm" object. This object is used as a default datetime in the to_datetime() method, and it also used to validate inputs to the set() method.

The base object must use the year/month/day system. Most calendars use this system including Gregorian ("DateTime") and Julian. Note that this module has not been well tested with base objects from classes other than "DateTime.pm" class.

By default, newly created "DateTime::Incomplete" objects have no base.

Most methods provided by this class are designed to emulate the behavior of "DateTime.pm" whenever possible.

  • year
  • month
  • day
  • hour
  • minute
  • second
  • nanosecond
  • time_zone
  • locale

    These methods returns the field value for the object, or "undef".

    These values can also be accessed using the same alias methods available in "DateTime.pm", such as mon(), mday(), etc.

  • has_year
  • has_month
  • has_day
  • has_hour
  • has_minute
  • has_second
  • has_nanosecond
  • has_time_zone
  • has_locale
  • has_date
  • has_time

    Returns a boolean value indicating whether the corresponding component is defined.

    "has_date" tests for year, month, and day.

    "has_time" tests for hour, minute, and second.

  • has

        $has_date = $dti->has( 'year', 'month', 'day' );
        

    Returns a boolean value indicating whether all fields in the argument list are defined.

  • defined_fields

        @fields = $dti->defined_fields;   # list of field names
        

    Returns a list containing the names of the fields that are defined.

    The list order is: year, month, day, hour, minute, second, nanosecond, time_zone, locale.

  • datetime, ymd, date, hms, time, iso8601, mdy, dmy

    These are equivalent to DateTime stringification methods with the same name, except that the undefined fields are replaced by 'xx' or 'xxxx' as appropriate.

  • epoch
  • hires_epoch
  • is_dst
  • utc_rd_values
  • utc_rd_as_seconds

        my $epoch = $dti->epoch( base => $dt );
        

    These methods are equivalent to the "DateTime" methods with the same name.

    They all accept a "base" argument to use in order to calculate the method's return values.

    If no "base" argument is given, then "today" is used.

  • is_finite, is_infinite

    Incomplete dates are always "finite".

  • strftime( $format, ... )

    This method implements functionality similar to the strftime() method in C. However, if given multiple format strings, then it will return multiple scalars, one for each format string.

    See the "strftime Specifiers" section in the "DateTime.pm" documentation for a list of all possible format specifiers.

    Undefined fields are replaced by 'xx' or 'xxxx' as appropriate.

    The specification %s (epoch) is calculated using "today" as the base date, unless the object has a base datetime set.

Computed Values

All other accessors, such as day_of_week(), or week_year() 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 "undef"

Unimplemented Methods

The following "DateTime.pm" methods are not implemented in "DateTime::Incomplete", though some of them may be implemented in future versions:

  • add_duration
  • add
  • subtract_duration
  • subtract
  • subtract_datetime
  • subtract_datetime_absolute
  • delta_md
  • delta_days
  • delta_ms
  • compare
  • compare_ignore_floating
  • DefaultLanguage

  • set

    Use this to set or undefine a datetime field:

      $dti->set( month => 12 );
      $dti->set( day => 24 );
      $dti->set( day => undef );
        

    This method takes the same arguments as the set() method in "DateTime.pm", but it can accept "undef" for any value.

  • set_time_zone

    This method accepts either a time zone object or a string that can be passed as the "name" parameter to "DateTime::TimeZone->new()".

    Unlike with "DateTime.pm", if the new time zone's offset is different from the previous time zone, no local time adjustment is made.

    You can remove time zone information by calling this method with the value "undef".

  • truncate( to => ... )

    This method allows you to reset some of the local time components in the object to their "zero" values. The "to" parameter is used to specify which values to truncate, and it may be one of "year", "month", "day", "hour", "minute", or "second". For example, if "month" is specified, then the local day becomes 1, and the hour, minute, and second all become 0.

    Note that the "to" parameter cannot be "week".

"DateTime::Incomplete" objects also have a number of methods unique to this class.

Support for this module is provided via the datetime@perl.org email list. See http://lists.perl.org/ for more details.

Flavio S. Glock <fglock[at]cpan.org>

With Ben Bennett <fiji[at]ayup.limey.net>, Claus Farber <claus[at]xn--frber-gra.muc.de>, Dave Rolsky <autarch[at]urth.org>, Eugene Van Der Pijll <pijll[at]gmx.net>, Rick Measham <rick[at]isite.net.au>, and the DateTime team.

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.

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/

2024-03-05 perl v5.38.2