The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

App::DateUtils - An assortment of date-/time-related CLI utilities

VERSION

This document describes version 0.09 of App::DateUtils (from Perl distribution App-DateUtils), released on 2016-06-29.

SYNOPSIS

This distribution provides the following command-line utilities related to date/time:

FUNCTIONS

dateconv(%args) -> any

Convert date to another format.

Examples:

  • Convert "today" to epoch:

     dateconv(date => "today"); # -> 1467158400
  • Convert epoch to ymd:

     dateconv(date => 1463702400, to => "ymd"); # -> "2016-05-20"

This function is not exported.

Arguments ('*' denotes required arguments):

  • date* => date

  • to => str (default: "epoch")

Return value: (any)

durconv(%args) -> any

Convert duration to another format.

Examples:

  • Convert "3h2m" to number of seconds:

     durconv(duration => "3h2m"); # -> 10920

This function is not exported.

Arguments ('*' denotes required arguments):

  • duration* => duration

  • to => str (default: "secs")

Return value: (any)

parse_date(%args) -> [status, msg, result, meta]

Parse date string(s) using one of several modules.

Examples:

  • Example #1:

     parse_date( dates => ["23 sep 2015", "tomorrow", "foo"]);

    Result:

     [
       200,
       "OK",
       [
         {
           as_datetime_obj => "2015-09-23T00:00:00",
           as_epoch        => 1442966400,
           is_parseable    => 1,
           original        => "23 sep 2015",
         },
         {
           as_datetime_obj => "2016-06-30T00:00:00",
           as_epoch        => 1467244800,
           is_parseable    => 1,
           original        => "tomorrow",
         },
         {
           error_msg    => "Invalid date format: foo at /home/s1/perl5/perlbrew/perls/perl-5.22.1/lib/site_perl/5.22.1/Perinci/Access.pm line 81. ",
           is_parseable => 0,
           original     => "foo",
         },
       ],
       {},
     ]

This function is not exported.

Arguments ('*' denotes required arguments):

  • dates* => array[str]

  • module => str (default: "DateTime::Format::Flexible")

  • time_zone => str

Returns an enveloped result (an array).

First element (status) is an integer containing HTTP status code (200 means OK, 4xx caller error, 5xx function error). Second element (msg) is a string containing error message, or 'OK' if status is 200. Third element (result) is optional, the actual result. Fourth element (meta) is called result metadata and is optional, a hash that contains extra information.

Return value: (any)

parse_date_using_df_alami_en(%args) -> [status, msg, result, meta]

Parse date string(s) using DateTime::Format::Alami::EN.

Examples:

  • Example #1:

     parse_date_using_df_alami_en(dates => ["23 May"]);

    Result:

     [
       200,
       "OK",
       [
         {
           as_datetime_obj => "2016-05-23T00:00:00",
           as_epoch        => 1463961600,
           is_parseable    => 1,
           original        => "23 May",
           pattern         => "p_dateymd",
         },
       ],
       {},
     ]
  • Example #2:

     parse_date_using_df_alami_en(dates => ["foo"]); # -> [200, "OK", [{ is_parseable => 0, original => "foo" }], {}]

This function is not exported.

Arguments ('*' denotes required arguments):

  • dates* => array[str]

  • time_zone => str

Returns an enveloped result (an array).

First element (status) is an integer containing HTTP status code (200 means OK, 4xx caller error, 5xx function error). Second element (msg) is a string containing error message, or 'OK' if status is 200. Third element (result) is optional, the actual result. Fourth element (meta) is called result metadata and is optional, a hash that contains extra information.

Return value: (any)

parse_date_using_df_alami_id(%args) -> [status, msg, result, meta]

Parse date string(s) using DateTime::Format::Alami::ID.

Examples:

  • Example #1:

     parse_date_using_df_alami_id(dates => ["23 Mei"]);

    Result:

     [200, "OK", [{ is_parseable => 0, original => "23 Mei" }], {}]
  • Example #2:

     parse_date_using_df_alami_id(dates => ["foo"]); # -> [200, "OK", [{ is_parseable => 0, original => "foo" }], {}]

This function is not exported.

Arguments ('*' denotes required arguments):

  • dates* => array[str]

  • time_zone => str

Returns an enveloped result (an array).

First element (status) is an integer containing HTTP status code (200 means OK, 4xx caller error, 5xx function error). Second element (msg) is a string containing error message, or 'OK' if status is 200. Third element (result) is optional, the actual result. Fourth element (meta) is called result metadata and is optional, a hash that contains extra information.

Return value: (any)

parse_date_using_df_flexible(%args) -> [status, msg, result, meta]

Parse date string(s) using DateTime::Format::Flexible.

Examples:

  • Example #1:

     parse_date_using_df_flexible(dates => ["23rd Jun"]);

    Result:

     [
       200,
       "OK",
       [
         {
           as_datetime_obj => "2016-06-23T00:00:00",
           as_epoch        => 1466640000,
           is_parseable    => 1,
           original        => "23rd Jun",
         },
       ],
       {},
     ]
  • Example #2:

     parse_date_using_df_flexible(dates => ["23 Dez"], lang => "de");

    Result:

     [
       200,
       "OK",
       [
         {
           as_datetime_obj => "2016-12-23T00:00:00",
           as_epoch        => 1482451200,
           is_parseable    => 1,
           original        => "23 Dez",
         },
       ],
       {},
     ]
  • Example #3:

     parse_date_using_df_flexible(dates => ["foo"]);

    Result:

     [
       200,
       "OK",
       [
         {
           error_msg    => "Invalid date format: foo at /home/s1/perl5/perlbrew/perls/perl-5.22.1/lib/site_perl/5.22.1/Perinci/Access.pm line 81. ",
           is_parseable => 0,
           original     => "foo",
         },
       ],
       {},
     ]

This function is not exported.

Arguments ('*' denotes required arguments):

  • dates* => array[str]

  • lang => str (default: "en")

  • time_zone => str

Returns an enveloped result (an array).

First element (status) is an integer containing HTTP status code (200 means OK, 4xx caller error, 5xx function error). Second element (msg) is a string containing error message, or 'OK' if status is 200. Third element (result) is optional, the actual result. Fourth element (meta) is called result metadata and is optional, a hash that contains extra information.

Return value: (any)

parse_date_using_df_natural(%args) -> [status, msg, result, meta]

Parse date string(s) using DateTime::Format::Natural.

Examples:

  • Example #1:

     parse_date_using_df_natural(dates => ["23rd Jun"]);

    Result:

     [
       200,
       "OK",
       [
         {
           as_datetime_obj => "2016-06-23T00:00:00",
           as_epoch        => 1466640000,
           is_parseable    => 1,
           original        => "23rd Jun",
         },
       ],
       {},
     ]
  • Example #2:

     parse_date_using_df_natural(dates => ["foo"]);

    Result:

     [
       200,
       "OK",
       [
         {
           error_msg    => "'foo' does not parse (perhaps you have some garbage?)",
           is_parseable => 0,
           original     => "foo",
         },
       ],
       {},
     ]

This function is not exported.

Arguments ('*' denotes required arguments):

  • dates* => array[str]

  • time_zone => str

Returns an enveloped result (an array).

First element (status) is an integer containing HTTP status code (200 means OK, 4xx caller error, 5xx function error). Second element (msg) is a string containing error message, or 'OK' if status is 200. Third element (result) is optional, the actual result. Fourth element (meta) is called result metadata and is optional, a hash that contains extra information.

Return value: (any)

parse_duration(%args) -> [status, msg, result, meta]

Parse duration string(s) using one of several modules.

This function is not exported.

Arguments ('*' denotes required arguments):

  • durations* => array[str]

  • module => str (default: "Time::Duration::Parse")

Returns an enveloped result (an array).

First element (status) is an integer containing HTTP status code (200 means OK, 4xx caller error, 5xx function error). Second element (msg) is a string containing error message, or 'OK' if status is 200. Third element (result) is optional, the actual result. Fourth element (meta) is called result metadata and is optional, a hash that contains extra information.

Return value: (any)

parse_duration_using_df_alami_en(%args) -> [status, msg, result, meta]

Parse duration string(s) using DateTime::Format::Alami::EN.

Examples:

  • Example #1:

     parse_duration_using_df_alami_en(durations => ["2h, 3mins"]);

    Result:

     [
       200,
       "OK",
       [
         {
           as_dtdur_obj => "PT2H3M",
           as_secs      => 7380,
           is_parseable => 1,
           original     => "2h, 3mins",
         },
       ],
       {},
     ]
  • Example #2:

     parse_duration_using_df_alami_en(durations => ["foo"]); # -> [200, "OK", [{ is_parseable => 0, original => "foo" }], {}]

This function is not exported.

Arguments ('*' denotes required arguments):

  • durations* => array[str]

Returns an enveloped result (an array).

First element (status) is an integer containing HTTP status code (200 means OK, 4xx caller error, 5xx function error). Second element (msg) is a string containing error message, or 'OK' if status is 200. Third element (result) is optional, the actual result. Fourth element (meta) is called result metadata and is optional, a hash that contains extra information.

Return value: (any)

parse_duration_using_df_alami_id(%args) -> [status, msg, result, meta]

Parse duration string(s) using DateTime::Format::Alami::ID.

Examples:

  • Example #1:

     parse_duration_using_df_alami_id(durations => ["2j, 3mnt"]);

    Result:

     [200, "OK", [{ is_parseable => 0, original => "2j, 3mnt" }], {}]
  • Example #2:

     parse_duration_using_df_alami_id(durations => ["foo"]); # -> [200, "OK", [{ is_parseable => 0, original => "foo" }], {}]

This function is not exported.

Arguments ('*' denotes required arguments):

  • durations* => array[str]

Returns an enveloped result (an array).

First element (status) is an integer containing HTTP status code (200 means OK, 4xx caller error, 5xx function error). Second element (msg) is a string containing error message, or 'OK' if status is 200. Third element (result) is optional, the actual result. Fourth element (meta) is called result metadata and is optional, a hash that contains extra information.

Return value: (any)

parse_duration_using_df_natural(%args) -> [status, msg, result, meta]

Parse duration string(s) using DateTime::Format::Natural.

Examples:

  • Example #1:

     parse_duration_using_df_natural(durations => ["for 2 weeks"]);

    Result:

     [
       200,
       "OK",
       [
         {
           as_dtdur_obj => "P2W",
           as_secs => 1209600,
           date1 => "2016-06-29T13:56:29",
           date2 => "2016-07-13T13:56:29",
           is_parseable => 1,
           original => "for 2 weeks",
         },
       ],
       {},
     ]
  • Example #2:

     parse_duration_using_df_natural(durations => ["from 23 Jun to 29 Jun"]);

    Result:

     [
       200,
       "OK",
       [
         {
           as_dtdur_obj => "PT13H56M29S",
           as_secs => 50189,
           date1 => "2016-06-29T13:56:29",
           date2 => "2016-06-29T00:00:00",
           is_parseable => 1,
           original => "from 23 Jun to 29 Jun",
         },
       ],
       {},
     ]
  • Example #3:

     parse_duration_using_df_natural(durations => ["foo"]);

    Result:

     [
       200,
       "OK",
       [
         {
           error_msg    => "'foo' does not parse (perhaps you have some garbage?)",
           is_parseable => 0,
           original     => "foo",
         },
       ],
       {},
     ]

This function is not exported.

Arguments ('*' denotes required arguments):

  • durations* => array[str]

Returns an enveloped result (an array).

First element (status) is an integer containing HTTP status code (200 means OK, 4xx caller error, 5xx function error). Second element (msg) is a string containing error message, or 'OK' if status is 200. Third element (result) is optional, the actual result. Fourth element (meta) is called result metadata and is optional, a hash that contains extra information.

Return value: (any)

parse_duration_using_td_parse(%args) -> [status, msg, result, meta]

Parse duration string(s) using Time::Duration::Parse.

Examples:

  • Example #1:

     parse_duration_using_td_parse(durations => ["2 days 13 hours"]);

    Result:

     [
       200,
       "OK",
       [
         { as_secs => 219600, is_parseable => 1, original => "2 days 13 hours" },
       ],
       {},
     ]
  • Example #2:

     parse_duration_using_td_parse(durations => ["foo"]);

    Result:

     [
       200,
       "OK",
       [
         {
           error_msg    => "Unknown timespec: foo at lib/App/DateUtils.pm line 295. ",
           is_parseable => 0,
           original     => "foo",
         },
       ],
       {},
     ]

This function is not exported.

Arguments ('*' denotes required arguments):

  • durations* => array[str]

Returns an enveloped result (an array).

First element (status) is an integer containing HTTP status code (200 means OK, 4xx caller error, 5xx function error). Second element (msg) is a string containing error message, or 'OK' if status is 200. Third element (result) is optional, the actual result. Fourth element (meta) is called result metadata and is optional, a hash that contains extra information.

Return value: (any)

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/App-DateUtils.

SOURCE

Source repository is at https://github.com/perlancar/perl-App-DateUtils.

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=App-DateUtils

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

SEE ALSO

dateparse, The official CLI for DateTime::Format::Natural.

App::datecalc

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2016 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.