—#!perl
# Note: This script is a CLI for Riap function /App/dateseq/dateseq
# and generated automatically using Perinci::CmdLine::Gen version 0.501
use
5.010001;
use
strict;
use
warnings;
our
$AUTHORITY
=
'cpan:PERLANCAR'
;
# AUTHORITY
our
$DATE
=
'2022-10-12'
;
# DATE
our
$DIST
=
'App-dateseq'
;
# DIST
our
$VERSION
=
'0.112'
;
# VERSION
my
$cmdline
= Perinci::CmdLine::Any->new(
url
=>
"/App/dateseq/dateseq"
,
program_name
=>
"dateseq"
,
read_config
=> 0,
read_env
=> 0,
);
$cmdline
->run;
# ABSTRACT: Generate a sequence of dates
# PODNAME: dateseq
__END__
=pod
=encoding UTF-8
=head1 NAME
dateseq - Generate a sequence of dates
=head1 VERSION
This document describes version 0.112 of dateseq (from Perl distribution App-dateseq), released on 2022-10-12.
=head1 SYNOPSIS
B<dateseq> [L<--business|/"--business">|L<--no-business|/"--business">|L<--nobusiness|/"--business">] [L<--business6|/"--business6">|L<--no-business6|/"--business6">|L<--nobusiness6|/"--business6">] [L<--eval|/"--eval=s, -e">=I<str>|L<-e|/"--eval=s, -e">=I<str>] [(L<--exclude-dow|/"--exclude-dow=s@">=L<date::dow_nums|Sah::Schema::date::dow_nums>)+|L<--exclude-dow-json|/"--exclude-dow=s@">=I<json>] [(L<--exclude-month|/"--exclude-month=s@">=L<date::month_nums|Sah::Schema::date::month_nums>)+|L<--exclude-month-json|/"--exclude-month=s@">=I<json>] [L<--format-class-attrs|/"--format-class-attrs=s">=I<s>|L<--format-class-attrs-json|/"--format-class-attrs=s">=I<json>] [L<--format-class|/"--format-class=s">=L<perl::modname|Sah::Schema::perl::modname>] [L<--format|/"--format=s">=I<name>|L<--json|/"--json">] [L<--header|/"--header=s">=I<str>] [(L<--include-dow|/"--include-dow=s@">=L<date::dow_nums|Sah::Schema::date::dow_nums>)+|L<--include-dow-json|/"--include-dow=s@">=I<json>] [(L<--include-month|/"--include-month=s@">=L<date::month_nums|Sah::Schema::date::month_nums>)+|L<--include-month-json|/"--include-month=s@">=I<json>] [L<--limit-monthly|/"--limit-monthly=s">=L<posint|Sah::Schema::posint>] [L<--limit-yearly|/"--limit-yearly=s">=L<posint|Sah::Schema::posint>] [L<--limit|/"--limit=s, -n">=L<posint|Sah::Schema::posint>|L<-n|/"--limit=s, -n">=L<posint|Sah::Schema::posint>] [L<--(no)naked-res|/"--naked-res">] [L<--page-result|/"--page-result">[=I<program>]|L<--view-result|/"--view-result">[=I<program>]] [L<--random|/"--random">] [L<--reverse|/"--reverse, -r">|L<-r|/"--reverse, -r">] [L<--strftime|/"--strftime=s, -f">=I<str>|L<-f|/"--strftime=s, -f">=I<str>] -- [L<from|/"--from=s">] [L<to|/"--to=s">] [L<increment|/"--increment=s, -i">]
See examples in the L</EXAMPLES> section.
=head1 DESCRIPTION
This utility is similar to Unix L<seq> command, except that it generates a
sequence of dates.
=head1 OPTIONS
C<*> marks required options.
=head2 Main options
=over
=item B<--from>=I<s>
Starting date.
Can also be specified as the 1st command-line argument.
=item B<--header>=I<s>
Add a header row.
=item B<--increment>=I<s>, B<-i>
Can also be specified as the 3rd command-line argument.
=item B<--limit-monthly>=I<s>
Only output at most this number of dates for each month.
=item B<--limit-yearly>=I<s>
Only output at most this number of dates for each year.
=item B<--limit>=I<s>, B<-n>
Only generate a certain amount of dates.
=item B<--random>
Instead of incrementing/decrementing monotonically, generate random date between --to and --from.
If you specify this, you have to specify C<--to> I<and> C<--from>.
Also, currently, if you also specify C<--limit-yearly> or C<--limit-monthly>, the
script may hang because it runs out of dates, so be careful when specifying
these options combined.
=item B<--reverse>, B<-r>
Decrement instead of increment.
=item B<--to>=I<s>
End date, if not specified will generate an infinite* stream of dates.
Can also be specified as the 2nd command-line argument.
=back
=head2 Filtering options
=over
=item B<--business>
Only list business days (Mon-Fri), or non-business days.
=item B<--business6>
Only list business days (Mon-Sat), or non-business days.
=item B<--exclude-dow-json>=I<s>
Do not show dates with these day-of-weeks (JSON-encoded).
See C<--exclude-dow>.
=item B<--exclude-dow>=I<s@>
Do not show dates with these day-of-weeks.
Can be specified multiple times.
=item B<--exclude-month-json>=I<s>
Do not show dates with these month numbers (JSON-encoded).
See C<--exclude-month>.
=item B<--exclude-month>=I<s@>
Do not show dates with these month numbers.
Can be specified multiple times.
=item B<--include-dow-json>=I<s>
Only show dates with these day-of-weeks (JSON-encoded).
See C<--include-dow>.
=item B<--include-dow>=I<s@>
Only show dates with these day-of-weeks.
Can be specified multiple times.
=item B<--include-month-json>=I<s>
Only show dates with these month numbers (JSON-encoded).
See C<--include-month>.
=item B<--include-month>=I<s@>
Only show dates with these month numbers.
Can be specified multiple times.
=back
=head2 Formatting options
=over
=item B<--format-class-attrs-json>=I<s>
Arguments to pass to constructor of DateTime::Format::* class (JSON-encoded).
See C<--format-class-attrs>.
=item B<--format-class-attrs>=I<s>
Arguments to pass to constructor of DateTime::Format::* class.
=item B<--format-class>=I<s>
Use a DateTime::Format::* class for formatting.
By default, L<DateTime::Format::Strptime> is used with pattern set from the
<strftime> option.
=item B<--strftime>=I<s>, B<-f>
strftime() format for each date.
Default is C<%Y-%m-%d>, unless when hour/minute/second is specified, then it is
C<%Y-%m-%dT%H:%M:%S>.
C<dateseq> actually uses L<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
=back
=head2 Output options
=over
=item B<--eval>=I<s>, B<-e>
Run perl code for each date.
Specified perl code will receive the date as DateTime object in C<$_>and expected
to return result to print.
=item B<--format>=I<s>
Choose output format, e.g. json, text.
Default value:
undef
Output can be displayed in multiple formats, and a suitable default format is
chosen depending on the application and/or whether output destination is
interactive terminal (i.e. whether output is piped). This option specifically
chooses an output format.
=item B<--json>
Set output format to json.
=item B<--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
C<--naked-res> so you just get:
[1,2,3]
=item B<--page-result>
Filter output through a pager.
This option will pipe the output to a specified pager program. If pager program
is not specified, a suitable default e.g. C<less> is chosen.
=item B<--view-result>
View output using a viewer.
This option will first save the output to a temporary file, then open a viewer
program to view the temporary file. If a viewer program is not chosen, a
suitable default, e.g. the browser, is chosen.
=back
=head2 Other options
=over
=item B<--help>, B<-h>, B<-?>
Display help message and exit.
=item B<--version>, B<-v>
Display program's version and exit.
=back
=head1 COMPLETION
This script has shell tab completion capability with support for several
shells.
=head2 bash
To activate bash completion for this script, put:
complete -C dateseq dateseq
in your bash startup (e.g. F<~/.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 L<cpanm-shcompgen>
which can activate shell completion for scripts immediately.
=head2 tcsh
To activate tcsh completion for this script, put:
complete dateseq 'p/*/`dateseq`/'
in your tcsh startup (e.g. F<~/.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 L<shcompgen> (see above).
=head2 other shells
For fish and zsh, install L<shcompgen> as described above.
=head1 EXAMPLES
=head2 Generate "infinite" dates from today
% dateseq
=head2 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
=head2 Generate dates from yesterday to 2 weeks from now
% dateseq yesterday "2 weeks from now"
2022-10-11T00:00:00
2022-10-12T00:00:00
... 12 more lines ...
2022-10-25T00:00:00
2022-10-26T00:00:00
=head2 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
=head2 Generate "infinite" dates from 2015-01-01 (reverse)
% dateseq 2015-01-01 -r
=head2 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
=head2 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
=head2 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)
=head2 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
=head2 Show the first business day (Mon-Fri) of each month in 2021
% dateseq 2021-01-01 2021-12-13 --business --limit-monthly 1 -f "%Y-%m-%d(%a)"
2021-01-01(Fri)
2021-02-01(Mon)
2021-03-01(Mon)
2021-04-01(Thu)
2021-05-03(Mon)
... 3 more lines ...
2021-09-01(Wed)
2021-10-01(Fri)
2021-11-01(Mon)
2021-12-01(Wed)
=head2 Show the last business day (Mon-Fri) of each month in 2021
% dateseq 2021-12-31 2021-01-01 -r --business --limit-monthly 1 -f "%Y-%m-%d(%a)"
2021-12-31(Fri)
2021-11-30(Tue)
2021-10-29(Fri)
2021-09-30(Thu)
2021-08-31(Tue)
... 3 more lines ...
2021-04-30(Fri)
2021-03-31(Wed)
2021-02-26(Fri)
2021-01-29(Fri)
=head2 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)"
=head2 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)"
=head2 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
=head2 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
=head2 List non-holidays in 2015 (using Indonesian holidays)
% setop --diff <(dateseq 2015-01-01 2015-12-31) <(list-idn-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
See also L<dateseq-idn> as alternative.
=head2 List non-holidays business days in 2015 (using Indonesian holidays)
% setop --diff <(dateseq 2015-01-01 2015-12-31 --business) <(list-idn-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
See also L<dateseq-idn> as alternative.
=head2 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'
=head2 Use %q (see DateTimeX::strftimeq)
% dateseq 2020-12-24 2021-01-15 -f '%Y-%m-%d%( $_->day_of_week == 7 ? "su" : "" )q'
2020-12-24
2020-12-25
2020-12-26
2020-12-27su
2020-12-28
... 14 more lines ...
2021-01-12
2021-01-13
2021-01-14
2021-01-15
=head2 Print first and last days of each month of 2021
% dateseq 2021-01-01 2021-12-01 --increment '1 month' -e 'my $dt2 = $_->clone; $dt2->add(months=>1); $dt2->add(days => -1); $_->ymd . " " . $dt2->ymd'
2021-01-01 2021-01-31
2021-02-01 2021-02-28
2021-03-01 2021-03-31
2021-04-01 2021-04-30
2021-05-01 2021-05-31
... 3 more lines ...
2021-09-01 2021-09-30
2021-10-01 2021-10-31
2021-11-01 2021-11-30
2021-12-01 2021-12-31
=head2 Retrieve MetaCPAN releases data for 2020, saved in monthly JSON files
% dateseq 2020-01-01 2020-12-01 --increment '1 month' -e 'my $dt2 = $_->clone; $dt2->add(months=>1); $dt2->add(days => -1); sprintf "list-metacpan-releases --from-date %sT00:00:00 --to-date %sT23:59:59 --json > %04d%02d.json", $_->ymd, $dt2->ymd, $_->year, $_->month' | bash
=head2 Generate 100 random dates between a certain range
% dateseq --random --from "1 year ago" --to "1 year from now" --limit 100
2022-09-08T14:55:06
2022-03-20T12:07:01
... 96 more lines ...
2022-01-02T07:23:33
2022-12-31T03:43:00
=head1 HOMEPAGE
Please visit the project's homepage at L<https://metacpan.org/release/App-dateseq>.
=head1 SOURCE
Source repository is at L<https://github.com/perlancar/perl-App-dateseq>.
=head1 SEE ALSO
L<durseq>. Produce sequence of date durations.
L<dateseq-idn>. A wrapper for dateseq, with built-in support for Indonesian holidays.
L<seq>.
L<seq-pl>. Perl variant of seq.
=head1 AUTHOR
perlancar <perlancar@cpan.org>
=head1 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 L<Dist::Zilla>,
L<Dist::Zilla::PluginBundle::Author::PERLANCAR>,
L<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.
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2022, 2021, 2020, 2019, 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.
=head1 BUGS
Please report any bugs or feature requests on the bugtracker website L<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.
=cut