The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

dateseq - Generate a sequence of dates

VERSION

This document describes version 0.100 of dateseq (from Perl distribution App-dateseq), released on 2020-04-30.

SYNOPSIS

Usage:

 % dateseq [--business] [--business6] [--exclude-dow-json=s]
     [--exclude-dow=s+] [--exclude-month-json=s] [--exclude-month=s+]
     [-f=s] [--format-class-attrs-json=s] [--format-class-attrs=s]
     [--format-class=s] [--format=name] [--header=s] [--include-dow-json=s]
     [--include-dow=s+] [--include-month-json=s] [--include-month=s+]
     [--json] [--limit=s] [-n=s] [--(no)naked-res] [--no-business]
     [--no-business6] [--nobusiness] [--nobusiness6]
     [--page-result[=program]] [-r] [--reverse] [--strftime=s] [from] [to]
     [increment]

Examples:

Generate "infinite" dates from today:

 % dateseq

Generate dates from 2015-01-01 to 2015-01-31:

 % dateseq 2015-01-01 2015-01-31
 2015-01-01
 2015-01-02
 ... 27 more lines ...
 2015-01-30
 2015-01-31

Generate dates from yesterday to 2 weeks from now:

 % dateseq yesterday "2 weeks from now"
 2020-04-29T00:00:00
 2020-04-30T00:00:00
 ... 12 more lines ...
 2020-05-13T00:00:00
 2020-05-14T00:00:00

Generate dates from 2015-01-31 to 2015-01-01 (reverse):

 % dateseq 2015-01-31 2015-01-01 -r
 2015-01-31
 2015-01-30
 ... 27 more lines ...
 2015-01-02
 2015-01-01

Generate "infinite" dates from 2015-01-01 (reverse):

 % dateseq 2015-01-01 -r

Generate 10 dates from 2015-01-01:

 % dateseq 2015-01-01 -n 10
 2015-01-01
 2015-01-02
 ... 6 more lines ...
 2015-01-09
 2015-01-10

Generate dates with increment of 3 days:

 % dateseq 2015-01-01 2015-01-31 -i P3D
 2015-01-01
 2015-01-04
 ... 7 more lines ...
 2015-01-28
 2015-01-31

Generate first 20 business days (Mon-Fri) after 2015-01-01:

 % dateseq 2015-01-01 --business -n 20 -f "%Y-%m-%d(%a)"
 2015-01-01(Thu)
 2015-01-02(Fri)
 2015-01-05(Mon)
 2015-01-06(Tue)
 2015-01-07(Wed)
 ... 11 more lines ...
 2015-01-23(Fri)
 2015-01-26(Mon)
 2015-01-27(Tue)
 2015-01-28(Wed)

Generate first 5 non-business days (Sat-Sun) after 2015-01-01:

 % dateseq 2015-01-01 --no-business -n 5
 2015-01-03
 2015-01-04
 2015-01-10
 2015-01-11
 2015-01-17

Show Mondays, Wednesdays, and Fridays between 2015-01-01 and 2015-02-28:

 % dateseq 2015-01-01 2015-02-28 --include-dow Mo,We,Fr -f "%Y-%m-%d(%a)"

Show dates (except Mondays) after 2015-01-01 and 2015-02-28:

 % dateseq 2015-01-01 2015-02-28 --exclude-dow Mo -f "%Y-%m-%d(%a)"

Generate a CSV data:

 % dateseq 2010-01-01 2015-01-31 -f "%Y,%m,%d" --header "year,month,day"
 year,month,day
 2010,01,01
 ... 1854 more lines ...
 2015,01,30
 2015,01,31

Generate periods (YYYY-MM):

 % dateseq 2010-01-01 2015-12-31 -i P1M -f "%Y-%m"
 2010-01
 2010-02
 ... 68 more lines ...
 2015-11
 2015-12

List non-holidays in 2015 (using Indonesian holidays):

 % setop --diff <(dateseq 2015-01-01 2015-12-31) <(list-id-holidays --year 2015)
 2015-01-02
 2015-01-04
 2015-01-05
 2015-01-06
 2015-01-07
 ... 336 more lines ...
 2015-12-28
 2015-12-29
 2015-12-30
 2015-12-31

List non-holidays business days in 2015 (using Indonesian holidays):

 % setop --diff <(dateseq 2015-01-01 2015-12-31 --business) <(list-id-holidays --year 2015)
 2015-01-02
 2015-01-05
 2015-01-06
 2015-01-07
 2015-01-08
 ... 236 more lines ...
 2015-12-28
 2015-12-29
 2015-12-30
 2015-12-31

Use with fsql:

 % dateseq 2010-01-01 2015-12-01 -f "%Y,%m" -i P1M --header "year,month" | fsql --add-csv - --add-csv data.csv -F YEAR -F MONTH 'SELECT year, month, data1 FROM stdin WHERE YEAR(data.date)=year AND MONTH(data.date)=month'

DESCRIPTION

This utility is similar to Unix seq command, except that it generates a sequence of dates.

OPTIONS

* marks required options.

Main options

--from=s

Starting date.

--header=s

Add a header row.

--increment=s, -i
--limit=s, -n

Only generate a certain amount of numbers.

--reverse, -r

Decrement instead of increment.

--to=s

End date, if not specified will generate an infinite* stream of dates.

Filtering options

--business

Only list business days (Mon-Fri), or non-business days.

--business6

Only list business days (Mon-Sat), or non-business days.

--exclude-dow-json=s

Do not show dates with these day-of-weeks (JSON-encoded).

See --exclude-dow.

--exclude-dow=s@

Do not show dates with these day-of-weeks.

Can be specified multiple times.

--exclude-month-json=s

Do not show dates with these month numbers (JSON-encoded).

See --exclude-month.

--exclude-month=s@

Do not show dates with these month numbers.

Can be specified multiple times.

--include-dow-json=s

Only show dates with these day-of-weeks (JSON-encoded).

See --include-dow.

--include-dow=s@

Only show dates with these day-of-weeks.

Can be specified multiple times.

--include-month-json=s

Only show dates with these month numbers (JSON-encoded).

See --include-month.

--include-month=s@

Only show dates with these month numbers.

Can be specified multiple times.

Formatting options

--format-class-attrs-json=s

Arguments to pass to constructor of DateTime::Format::* class (JSON-encoded).

See --format-class-attrs.

--format-class-attrs=s

Arguments to pass to constructor of DateTime::Format::* class.

--format-class=s

Use a DateTime::Format::* class for formatting.

By default, <pm:DateTime::Format::Strptime> is used with pattern set from the <strftime> option.

--strftime=s, -f

strftime() format for each date.

Default is `%Y-%m-%d`, unless when hour/minute/second is specified, then it is `%Y-%m-%dT%H:%M:%S`.

`dateseq` actually uses <pm:DateTimeX::strftimeq>, so you can embed Perl code for flexibility. For example:

    % dateseq 2019-11-19 2019-11-25 -f '%Y-%m-%d%( $_->day_of_week == 7 ? "su" : "" )q'

will print something like:

    2019-11-19
    2019-11-20
    2019-11-21
    2019-11-22
    2019-11-23
    2019-11-24su
    2019-11-25

Output options

--format=s

Choose output format, e.g. json, text.

Default value:

 undef
--json

Set output format to json.

--naked-res

When outputing as JSON, strip result envelope.

Default value:

 0

By default, when outputing as JSON, the full enveloped result is returned, e.g.:

    [200,"OK",[1,2,3],{"func.extra"=>4}]

The reason is so you can get the status (1st element), status message (2nd element) as well as result metadata/extra result (4th element) instead of just the result (3rd element). However, sometimes you want just the result, e.g. when you want to pipe the result for more post-processing. In this case you can use `--naked-res` so you just get:

    [1,2,3]
--page-result

Filter output through a pager.

Other options

--help, -h, -?

Display help message and exit.

--version, -v

Display program's version and exit.

COMPLETION

This script has shell tab completion capability with support for several shells.

bash

To activate bash completion for this script, put:

 complete -C dateseq dateseq

in your bash startup (e.g. ~/.bashrc). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately.

It is recommended, however, that you install modules using cpanm-shcompgen which can activate shell completion for scripts immediately.

tcsh

To activate tcsh completion for this script, put:

 complete dateseq 'p/*/`dateseq`/'

in your tcsh startup (e.g. ~/.tcshrc). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately.

It is also recommended to install shcompgen (see above).

other shells

For fish and zsh, install shcompgen as described above.

HOMEPAGE

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

SOURCE

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

BUGS

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

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

durseq. Produce sequence of date durations.

seq.

seq-pl. Perl variant of seq.

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2020, 2019, 2016, 2015 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.