NAME App::DateUtils - An assortment of date-/time-related CLI utilities VERSION This document describes version 0.128 of App::DateUtils (from Perl distribution App-DateUtils), released on 2024-03-07. SYNOPSIS This distribution provides the following command-line utilities related to date/time: 1. dateconv 2. datediff 3. durconv 4. parse-date 5. parse-date-using-df-alami-en 6. parse-date-using-df-alami-id 7. parse-date-using-df-flexible 8. parse-date-using-df-natural 9. parse-duration 10. parse-duration-using-df-alami-en 11. parse-duration-using-df-alami-id 12. parse-duration-using-df-natural 13. parse-duration-using-td-parse 14. strftime 15. strftimeq FUNCTIONS dateconv Usage: dateconv(%args) -> any Convert date from one format to another. Examples: * Convert "today" to epoch: dateconv(date => "today"); # -> 1709769600 * Convert epoch to ymd: dateconv(date => 1463702400, to => "ymd"); # -> "2016-05-20" * Convert epoch to iso8601: dateconv(date => 1580446441, to => "iso8601"); # -> "2020-01-31T04:54:01Z" * Convert iso8601 to epoch: dateconv(date => "2020-01-31T04:54:01Z", to => "epoch"); # -> 1580446441 * Show all possible conversions: dateconv(date => "now", to => "ALL"); Result: { epoch => 1709802621, iso8601 => "2024-03-07T09:10:21.491146Z", ymd => "2024-03-07", } This function is not exported. Arguments ('*' denotes required arguments): * date* => *date* (No description) * to => *str* (default: "epoch") (No description) Return value: (any) datediff Usage: datediff(%args) -> any Diff (subtract) two dates, show as ISO8601 duration. Examples: * Example #1: datediff(date1 => "2019-06-18T20:08:42", date2 => "2019-06-19T06:02:03"); # -> "PT9H53M21S" * Example #2: datediff( date1 => "2019-06-18T20:08:42", date2 => "2019-06-19T06:02:03", as => "hms" ); Result: "09:53:21" * Example #3: datediff( date1 => "2019-06-18T20:08:42", date2 => "2019-06-22T06:02:03", as => "concise_hms" ); Result: "3d 09:53:21" * Example #4: datediff( date1 => "2019-06-18T20:08:42", date2 => "2019-06-19T06:02:03", as => "seconds" ); Result: 35601 This function is not exported. Arguments ('*' denotes required arguments): * as => *str* (default: "iso8601") (No description) * date1* => *date* (No description) * date2* => *date* (No description) Return value: (any) durconv Usage: durconv(%args) -> any Convert duration from one format to another. Examples: * Convert "3h2m" to number of seconds: durconv(duration => "3h2m"); # -> 10920 * Convert "3h2m" to iso8601: durconv(duration => "3h2m", to => "iso8601"); # -> "PT3H2M" * Show all possible conversions: durconv(duration => "3h2m", to => "ALL"); Result: { hash => { hours => 3, minutes => 2 }, iso8601 => "PT3H2M", secs => 10920, } This function is not exported. Arguments ('*' denotes required arguments): * duration* => *duration* (No description) * to => *str* (default: "secs") (No description) Return value: (any) parse_date Usage: parse_date(%args) -> [$status_code, $reason, $payload, \%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", [ { module => "DateTime::Format::Flexible", original => "23 sep 2015", is_parseable => 1, as_epoch => 1442966400, as_datetime_obj => "2015-09-23T00:00:00", as_datetime_obj_tz_local => "2015-09-23T00:00:00+07:00", as_datetime_obj_tz_utc => "2015-09-22T17:00:00Z", }, { module => "DateTime::Format::Flexible", original => "tomorrow", is_parseable => 1, as_epoch => 1709856000, as_datetime_obj => "2024-03-08T00:00:00", as_datetime_obj_tz_local => "2024-03-08T00:00:00+07:00", as_datetime_obj_tz_utc => "2024-03-07T17:00:00Z", }, { module => "DateTime::Format::Flexible", original => "foo", is_parseable => 0, error_msg => "Invalid date format: foo at /home/u1/perl5/perlbrew/perls/perl-5.38.2/lib/site_perl/5.38.2/Perinci/Access.pm line 81. ", }, ], { "table.fields" => [ "module", "original", "is_parseable", "as_epoch", "as_datetime_obj", "as_datetime_obj_tz_local", "as_datetime_obj_tz_utc", "error_msg", ], }, ] This function is not exported. Arguments ('*' denotes required arguments): * all_modules => *bool* Parse using all installed modules and return all the result at once. * dates* => *array[str]* (No description) * module => *str* (default: "DateTime::Format::Flexible") (No description) * time_zone => *str* (No description) Returns an enveloped result (an array). First element ($status_code) is an integer containing HTTP-like status code (200 means OK, 4xx caller error, 5xx function error). Second element ($reason) is a string containing error message, or something like "OK" if status is 200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth element (%result_meta) is called result metadata and is optional, a hash that contains extra information, much like how HTTP response headers provide additional metadata. Return value: (any) parse_date_using_df_alami_en Usage: parse_date_using_df_alami_en(%args) -> [$status_code, $reason, $payload, \%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", [ { module => "DateTime::Format::Alami::EN", original => "23 May", is_parseable => 1, as_epoch => 1716422400, as_datetime_obj => "2024-05-23T00:00:00", as_datetime_obj_tz_local => "2024-05-23T07:00:00+07:00", as_datetime_obj_tz_utc => "2024-05-23T00:00:00Z", pattern => "p_dateymd", }, ], { "table.fields" => [ "module", "original", "is_parseable", "as_epoch", "as_datetime_obj", "as_datetime_obj_tz_local", "as_datetime_obj_tz_utc", "error_msg", ], }, ] * Example #2: parse_date_using_df_alami_en(dates => ["foo"]); Result: [ 200, "OK", [ { module => "DateTime::Format::Alami::EN", original => "foo", is_parseable => 0, }, ], { "table.fields" => [ "module", "original", "is_parseable", "as_epoch", "as_datetime_obj", "as_datetime_obj_tz_local", "as_datetime_obj_tz_utc", "error_msg", ], }, ] This function is not exported. Arguments ('*' denotes required arguments): * dates* => *array[str]* (No description) * time_zone => *str* (No description) Returns an enveloped result (an array). First element ($status_code) is an integer containing HTTP-like status code (200 means OK, 4xx caller error, 5xx function error). Second element ($reason) is a string containing error message, or something like "OK" if status is 200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth element (%result_meta) is called result metadata and is optional, a hash that contains extra information, much like how HTTP response headers provide additional metadata. Return value: (any) parse_date_using_df_alami_id Usage: parse_date_using_df_alami_id(%args) -> [$status_code, $reason, $payload, \%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", [ { module => "DateTime::Format::Alami::ID", original => "23 Mei", is_parseable => 1, as_epoch => 1716422400, as_datetime_obj => "2024-05-23T00:00:00", as_datetime_obj_tz_local => "2024-05-23T07:00:00+07:00", as_datetime_obj_tz_utc => "2024-05-23T00:00:00Z", pattern => "p_dateymd", }, ], { "table.fields" => [ "module", "original", "is_parseable", "as_epoch", "as_datetime_obj", "as_datetime_obj_tz_local", "as_datetime_obj_tz_utc", "error_msg", ], }, ] * Example #2: parse_date_using_df_alami_id(dates => ["foo"]); Result: [ 200, "OK", [ { module => "DateTime::Format::Alami::ID", original => "foo", is_parseable => 0, }, ], { "table.fields" => [ "module", "original", "is_parseable", "as_epoch", "as_datetime_obj", "as_datetime_obj_tz_local", "as_datetime_obj_tz_utc", "error_msg", ], }, ] This function is not exported. Arguments ('*' denotes required arguments): * dates* => *array[str]* (No description) * time_zone => *str* (No description) Returns an enveloped result (an array). First element ($status_code) is an integer containing HTTP-like status code (200 means OK, 4xx caller error, 5xx function error). Second element ($reason) is a string containing error message, or something like "OK" if status is 200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth element (%result_meta) is called result metadata and is optional, a hash that contains extra information, much like how HTTP response headers provide additional metadata. Return value: (any) parse_date_using_df_flexible Usage: parse_date_using_df_flexible(%args) -> [$status_code, $reason, $payload, \%result_meta] Parse date string(s) using DateTime::Format::Flexible. Examples: * Example #1: parse_date_using_df_flexible(dates => ["23rd Jun"]); Result: [ 200, "OK", [ { module => "DateTime::Format::Flexible", original => "23rd Jun", is_parseable => 1, as_epoch => 1719100800, as_datetime_obj => "2024-06-23T00:00:00", as_datetime_obj_tz_local => "2024-06-23T00:00:00+07:00", as_datetime_obj_tz_utc => "2024-06-22T17:00:00Z", }, ], { "table.fields" => [ "module", "original", "is_parseable", "as_epoch", "as_datetime_obj", "as_datetime_obj_tz_local", "as_datetime_obj_tz_utc", "error_msg", ], }, ] * Example #2: parse_date_using_df_flexible(dates => ["23 Dez"], lang => "de"); Result: [ 200, "OK", [ { module => "DateTime::Format::Flexible(de)", original => "23 Dez", is_parseable => 1, as_epoch => 1734912000, as_datetime_obj => "2024-12-23T00:00:00", as_datetime_obj_tz_local => "2024-12-23T00:00:00+07:00", as_datetime_obj_tz_utc => "2024-12-22T17:00:00Z", }, ], { "table.fields" => [ "module", "original", "is_parseable", "as_epoch", "as_datetime_obj", "as_datetime_obj_tz_local", "as_datetime_obj_tz_utc", "error_msg", ], }, ] * Example #3: parse_date_using_df_flexible(dates => ["foo"]); Result: [ 200, "OK", [ { module => "DateTime::Format::Flexible", original => "foo", is_parseable => 0, error_msg => "Invalid date format: foo at /home/u1/perl5/perlbrew/perls/perl-5.38.2/lib/site_perl/5.38.2/Perinci/Access.pm line 81. ", }, ], { "table.fields" => [ "module", "original", "is_parseable", "as_epoch", "as_datetime_obj", "as_datetime_obj_tz_local", "as_datetime_obj_tz_utc", "error_msg", ], }, ] This function is not exported. Arguments ('*' denotes required arguments): * dates* => *array[str]* (No description) * lang => *str* (default: "en") (No description) * time_zone => *str* (No description) Returns an enveloped result (an array). First element ($status_code) is an integer containing HTTP-like status code (200 means OK, 4xx caller error, 5xx function error). Second element ($reason) is a string containing error message, or something like "OK" if status is 200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth element (%result_meta) is called result metadata and is optional, a hash that contains extra information, much like how HTTP response headers provide additional metadata. Return value: (any) parse_date_using_df_natural Usage: parse_date_using_df_natural(%args) -> [$status_code, $reason, $payload, \%result_meta] Parse date string(s) using DateTime::Format::Natural. Examples: * Example #1: parse_date_using_df_natural(dates => ["23rd Jun"]); Result: [ 200, "OK", [ { module => "DateTime::Format::Natural", original => "23rd Jun", is_parseable => 1, as_epoch => 1719100800, as_datetime_obj => "2024-06-23T00:00:00", as_datetime_obj_tz_local => "2024-06-23T00:00:00+07:00", as_datetime_obj_tz_utc => "2024-06-22T17:00:00Z", }, ], { "table.fields" => [ "module", "original", "is_parseable", "as_epoch", "as_datetime_obj", "as_datetime_obj_tz_local", "as_datetime_obj_tz_utc", "error_msg", ], }, ] * Example #2: parse_date_using_df_natural(dates => ["foo"]); Result: [ 200, "OK", [ { module => "DateTime::Format::Natural", original => "foo", is_parseable => 0, error_msg => "'foo' does not parse (perhaps you have some garbage?)", }, ], { "table.fields" => [ "module", "original", "is_parseable", "as_epoch", "as_datetime_obj", "as_datetime_obj_tz_local", "as_datetime_obj_tz_utc", "error_msg", ], }, ] This function is not exported. Arguments ('*' denotes required arguments): * dates* => *array[str]* (No description) * time_zone => *str* (No description) Returns an enveloped result (an array). First element ($status_code) is an integer containing HTTP-like status code (200 means OK, 4xx caller error, 5xx function error). Second element ($reason) is a string containing error message, or something like "OK" if status is 200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth element (%result_meta) is called result metadata and is optional, a hash that contains extra information, much like how HTTP response headers provide additional metadata. Return value: (any) parse_duration Usage: parse_duration(%args) -> [$status_code, $reason, $payload, \%result_meta] Parse duration string(s) using one of several modules. This function is not exported. Arguments ('*' denotes required arguments): * all_modules => *bool* Parse using all installed modules and return all the result at once. * durations* => *array[str]* (No description) * module => *str* (default: "Time::Duration::Parse") (No description) Returns an enveloped result (an array). First element ($status_code) is an integer containing HTTP-like status code (200 means OK, 4xx caller error, 5xx function error). Second element ($reason) is a string containing error message, or something like "OK" if status is 200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth element (%result_meta) is called result metadata and is optional, a hash that contains extra information, much like how HTTP response headers provide additional metadata. Return value: (any) parse_duration_using_df_alami_en Usage: parse_duration_using_df_alami_en(%args) -> [$status_code, $reason, $payload, \%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", [ { module => "DateTime::Format::Alami::EN", original => "2h, 3mins", is_parseable => 1, as_secs => 7380, as_dtdur_obj => "PT2H3M", }, ], { "table.fields" => [ "module", "original", "is_parseable", "as_secs", "as_dtdur_obj", "error_msg", ], }, ] * Example #2: parse_duration_using_df_alami_en(durations => ["foo"]); Result: [ 200, "OK", [ { module => "DateTime::Format::Alami::EN", original => "foo", is_parseable => 0, }, ], { "table.fields" => [ "module", "original", "is_parseable", "as_secs", "as_dtdur_obj", "error_msg", ], }, ] This function is not exported. Arguments ('*' denotes required arguments): * durations* => *array[str]* (No description) Returns an enveloped result (an array). First element ($status_code) is an integer containing HTTP-like status code (200 means OK, 4xx caller error, 5xx function error). Second element ($reason) is a string containing error message, or something like "OK" if status is 200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth element (%result_meta) is called result metadata and is optional, a hash that contains extra information, much like how HTTP response headers provide additional metadata. Return value: (any) parse_duration_using_df_alami_id Usage: parse_duration_using_df_alami_id(%args) -> [$status_code, $reason, $payload, \%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", [ { module => "DateTime::Format::Alami::ID", original => "2j, 3mnt", is_parseable => 1, as_secs => 7380, as_dtdur_obj => "PT2H3M", }, ], { "table.fields" => [ "module", "original", "is_parseable", "as_secs", "as_dtdur_obj", "error_msg", ], }, ] * Example #2: parse_duration_using_df_alami_id(durations => ["foo"]); Result: [ 200, "OK", [ { module => "DateTime::Format::Alami::ID", original => "foo", is_parseable => 0, }, ], { "table.fields" => [ "module", "original", "is_parseable", "as_secs", "as_dtdur_obj", "error_msg", ], }, ] This function is not exported. Arguments ('*' denotes required arguments): * durations* => *array[str]* (No description) Returns an enveloped result (an array). First element ($status_code) is an integer containing HTTP-like status code (200 means OK, 4xx caller error, 5xx function error). Second element ($reason) is a string containing error message, or something like "OK" if status is 200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth element (%result_meta) is called result metadata and is optional, a hash that contains extra information, much like how HTTP response headers provide additional metadata. Return value: (any) parse_duration_using_df_natural Usage: parse_duration_using_df_natural(%args) -> [$status_code, $reason, $payload, \%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", [ { module => "DateTime::Format::Natural", original => "for 2 weeks", is_parseable => 1, as_secs => 1209600.000768, as_dtdur_obj => "P14DT0.000768S", date2 => "2024-03-21T09:10:21", date1 => "2024-03-07T09:10:21", }, ], { "table.fields" => [ "module", "original", "is_parseable", "as_secs", "as_dtdur_obj", "error_msg", ], }, ] * Example #2: parse_duration_using_df_natural(durations => ["from 23 Jun to 29 Jun"]); Result: [ 200, "OK", [ { module => "DateTime::Format::Natural", original => "from 23 Jun to 29 Jun", is_parseable => 1, as_secs => 9757178.285926, as_dtdur_obj => "P3M21DT14H49M38.285926S", date1 => "2024-03-07T09:10:21", date2 => "2024-06-29T00:00:00", }, ], { "table.fields" => [ "module", "original", "is_parseable", "as_secs", "as_dtdur_obj", "error_msg", ], }, ] * Example #3: parse_duration_using_df_natural(durations => ["foo"]); Result: [ 200, "OK", [ { module => "DateTime::Format::Natural", original => "foo", is_parseable => 0, error_msg => "'foo' does not parse (perhaps you have some garbage?)", }, ], { "table.fields" => [ "module", "original", "is_parseable", "as_secs", "as_dtdur_obj", "error_msg", ], }, ] This function is not exported. Arguments ('*' denotes required arguments): * durations* => *array[str]* (No description) Returns an enveloped result (an array). First element ($status_code) is an integer containing HTTP-like status code (200 means OK, 4xx caller error, 5xx function error). Second element ($reason) is a string containing error message, or something like "OK" if status is 200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth element (%result_meta) is called result metadata and is optional, a hash that contains extra information, much like how HTTP response headers provide additional metadata. Return value: (any) parse_duration_using_td_parse Usage: parse_duration_using_td_parse(%args) -> [$status_code, $reason, $payload, \%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", [ { module => "Time::Duration::Parse", original => "2 days 13 hours", is_parseable => 1, as_secs => 219600, }, ], { "table.fields" => [ "module", "original", "is_parseable", "as_secs", "as_dtdur_obj", "error_msg", ], }, ] * Example #2: parse_duration_using_td_parse(durations => ["foo"]); Result: [ 200, "OK", [ { module => "Time::Duration::Parse", original => "foo", is_parseable => 0, error_msg => "Unknown timespec: foo at (eval 2220) line 385. ", }, ], { "table.fields" => [ "module", "original", "is_parseable", "as_secs", "as_dtdur_obj", "error_msg", ], }, ] This function is not exported. Arguments ('*' denotes required arguments): * durations* => *array[str]* (No description) Returns an enveloped result (an array). First element ($status_code) is an integer containing HTTP-like status code (200 means OK, 4xx caller error, 5xx function error). Second element ($reason) is a string containing error message, or something like "OK" if status is 200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth element (%result_meta) is called result metadata and is optional, a hash that contains extra information, much like how HTTP response headers provide additional metadata. Return value: (any) strftime Usage: strftime(%args) -> any Format date using strftime(). Examples: * Format current time as yyyy-mm-dd: strftime(format => "%Y-%m-%d"); # -> "2024-03-07" * Format a specific time as yyyy-mm-dd: strftime(format => "%Y-%m-%d", date => "tomorrow"); # -> "2024-03-08" This function is not exported. Arguments ('*' denotes required arguments): * date => *date* (No description) * format* => *str* (No description) Return value: (any) strftimeq Usage: strftimeq(%args) -> any Format date using strftimeq(). Examples: * Format current time as yyyy-mm-dd but add "Sun" when the date is Sunday: strftimeq(format => "%Y-%m-%d%( require Date::DayOfWeek; Date::DayOfWeek::dayofweek(\$_[3], \$_[4]+1, \$_[5]+1900) == 0 ? \"sun\":\"\" )q"); Result: "2024-03-07" strftimeq() is like POSIX's strftime(), but allows an extra conversion "%(...)q" to insert Perl code, for flexibility in customizing format. For more details, read Date::strftimeq. This function is not exported. Arguments ('*' denotes required arguments): * date => *date* (No description) * format* => *str* (No description) 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>. SEE ALSO dateparse. Perinci::To::POD=HASH(0x555af311e1c8). App::datecalc App::TimeZoneUtils AUTHOR perlancar <perlancar@cpan.org> CONTRIBUTING To contribute, you can send patches by email/via RT, or send pull requests on GitHub. Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via: % prove -l If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond that are considered a bug and can be reported to me. COPYRIGHT AND LICENSE This software is copyright (c) 2024, 2021, 2020, 2019, 2017, 2016, 2015 by perlancar <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. 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.