Skip to content

DateTimeFactory.pm

Denis T edited this page Feb 8, 2017 · 1 revision

Description

Encapsulates work with family of date objects (DateTime, DateTime::Duration, DateTime::Span and DateTime::SpanSet).

API

set_default_timezone(timezone): undef static

Sets timezone that will be used for new instances by default.

new(timezone): object

Returns module instance with passed time zone. If timezone parameter omitted default time zone used.

now(): object

Returns current time in current time zone. Dies if time zone is not set.

tomorrow(): object

Returns next day start time (midnight) in current time zone. Dies if time zone is not set.

epoch(unixtime): object

Returns DateTime object built from unix time with time zone set to current. Dies if time zone is not set.

  • unixtime - number of seconds since 1 January 1970.

cmp(left, right): number

Shortcut for DateTime->compare(left, right).

  • left - DateTime object.
  • right - DateTime object.

parse(inputstr): object

Parses input string with Date::Parse->str2time function and returns DateTime from resulting value. Returns undef if parsing fails.

  • inputstr - string contains date and time.

parse_rfc3339(inputstr): object

Parses input string with DateTime::Format::RFC3339->parse_datetime, sets current time zone to result and returns it. Dies if time zone is not set.

  • inputstr - string contains date and time in RFC3339 format.

dur(params): object

Shortcut for DateTime::Duration->new(params).

  • params - hash of parameters for DateTime::Duration->new.

durcmp(left, right, start): number

Shortcut for DateTime::Duration->compare(left, right, start).

  • left - DateTime::Duration object.
  • right - DateTime::Duration object.
  • start - DateTime object.

rfc3339(datetime): string

Returns string with DateTime object in RFC3339 format. Shortcut for DateTime::Format::RFC3339->format_datetime.

  • datetime - DateTime object.

span_d(datetime, data): object

Returns DateTime::Duration object created from DateTime and duration. Creates DateTime::Duration from data if it is not blessed object.

  • datetime - DateTime object.
  • data - DateTime::Duration' object or hash for DateTime::Duration->new'.

span_se(start, end): object

Shortcut for DateTime::Span->from_datetimes(start => start, before => end).

  • start - DateTime object.
  • end - DateTime object.

spanset(spans): object

Shortcut for DateTime::SpanSet->from_spans(spans).

  • spans - reference to array of DateTime::Span objects.

Tests

No tests.