App-durseq

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

            "Data::Sah::Coerce::perl::To_duration::From_float::seconds" : "0",
            "Data::Sah::Coerce::perl::To_duration::From_obj::datetime_duration" : "0",
            "Data::Sah::Coerce::perl::To_duration::From_str::human" : "0",
            "Data::Sah::Coerce::perl::To_duration::From_str::iso8601" : "0",
            "Data::Sah::Coerce::perl::To_str::From_str::normalize_perl_modname" : "0",
            "Data::Sah::Compiler::perl::TH::bool" : "0",
            "Data::Sah::Compiler::perl::TH::duration" : "0",
            "Data::Sah::Compiler::perl::TH::hash" : "0",
            "Data::Sah::Compiler::perl::TH::int" : "0",
            "Data::Sah::Compiler::perl::TH::str" : "0",
            "DateTime" : "0",
            "DateTime::Duration" : "0",
            "DateTime::Format::Duration::ISO8601" : "0",
            "Perinci::CmdLine::Any" : "0",
            "Perinci::CmdLine::Lite" : "1.820",
            "Sah::Schema::perl::modname" : "0",
            "Sah::Schema::true" : "0",
            "perl" : "5.010001",
            "strict" : "0",
            "warnings" : "0"
         }
      },
      "test" : {

META.yml  view on Meta::CPAN

  Data::Sah::Coerce::perl::To_duration::From_float::seconds: '0'
  Data::Sah::Coerce::perl::To_duration::From_obj::datetime_duration: '0'
  Data::Sah::Coerce::perl::To_duration::From_str::human: '0'
  Data::Sah::Coerce::perl::To_duration::From_str::iso8601: '0'
  Data::Sah::Coerce::perl::To_str::From_str::normalize_perl_modname: '0'
  Data::Sah::Compiler::perl::TH::bool: '0'
  Data::Sah::Compiler::perl::TH::duration: '0'
  Data::Sah::Compiler::perl::TH::hash: '0'
  Data::Sah::Compiler::perl::TH::int: '0'
  Data::Sah::Compiler::perl::TH::str: '0'
  DateTime: '0'
  DateTime::Duration: '0'
  DateTime::Format::Duration::ISO8601: '0'
  Perinci::CmdLine::Any: '0'
  Perinci::CmdLine::Lite: '1.820'
  Sah::Schema::perl::modname: '0'
  Sah::Schema::true: '0'
  perl: '5.010001'
  strict: '0'
  warnings: '0'
resources:
  bugtracker: https://rt.cpan.org/Public/Dist/Display.html?Name=App-durseq
  homepage: https://metacpan.org/release/App-durseq

Makefile.PL  view on Meta::CPAN

    "Data::Sah::Coerce::perl::To_duration::From_float::seconds" => 0,
    "Data::Sah::Coerce::perl::To_duration::From_obj::datetime_duration" => 0,
    "Data::Sah::Coerce::perl::To_duration::From_str::human" => 0,
    "Data::Sah::Coerce::perl::To_duration::From_str::iso8601" => 0,
    "Data::Sah::Coerce::perl::To_str::From_str::normalize_perl_modname" => 0,
    "Data::Sah::Compiler::perl::TH::bool" => 0,
    "Data::Sah::Compiler::perl::TH::duration" => 0,
    "Data::Sah::Compiler::perl::TH::hash" => 0,
    "Data::Sah::Compiler::perl::TH::int" => 0,
    "Data::Sah::Compiler::perl::TH::str" => 0,
    "DateTime" => 0,
    "DateTime::Duration" => 0,
    "DateTime::Format::Duration::ISO8601" => 0,
    "Perinci::CmdLine::Any" => 0,
    "Perinci::CmdLine::Lite" => "1.820",
    "Sah::Schema::perl::modname" => 0,
    "Sah::Schema::true" => 0,
    "strict" => 0,
    "warnings" => 0
  },
  "TEST_REQUIRES" => {
    "File::Spec" => 0,
    "IO::Handle" => 0,

Makefile.PL  view on Meta::CPAN

  "Data::Sah::Coerce::perl::To_duration::From_float::seconds" => 0,
  "Data::Sah::Coerce::perl::To_duration::From_obj::datetime_duration" => 0,
  "Data::Sah::Coerce::perl::To_duration::From_str::human" => 0,
  "Data::Sah::Coerce::perl::To_duration::From_str::iso8601" => 0,
  "Data::Sah::Coerce::perl::To_str::From_str::normalize_perl_modname" => 0,
  "Data::Sah::Compiler::perl::TH::bool" => 0,
  "Data::Sah::Compiler::perl::TH::duration" => 0,
  "Data::Sah::Compiler::perl::TH::hash" => 0,
  "Data::Sah::Compiler::perl::TH::int" => 0,
  "Data::Sah::Compiler::perl::TH::str" => 0,
  "DateTime" => 0,
  "DateTime::Duration" => 0,
  "DateTime::Format::Duration::ISO8601" => 0,
  "File::Spec" => 0,
  "IO::Handle" => 0,
  "IPC::Open3" => 0,
  "Perinci::CmdLine::Any" => 0,
  "Perinci::CmdLine::Lite" => "1.820",
  "Sah::Schema::perl::modname" => 0,
  "Sah::Schema::true" => 0,
  "Test::More" => 0,
  "strict" => 0,
  "warnings" => 0

README  view on Meta::CPAN


    This utility is similar to Perl script dateseq, except that it generates
    a sequence of durations instead of dates.

    This function is not exported.

    Arguments ('*' denotes required arguments):

    *   format_class => *perl::modname* (default: "ISO8601")

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

        By default, "ISO8601" (DateTime::Format::Duration::ISO8601) is used.

    *   format_class_attrs => *hash*

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

    *   from => *duration*

        Starting duration.

    *   increment => *duration*

        Increment, default is one day (P1D).

    *   limit => *int*

dist.ini  view on Meta::CPAN

read_config=0

[@Author::PERLANCAR]
:version=0.598

[Prereqs]
perl=5.010001
strict=0
warnings=0
Complete::Module=0
;DateTime=0
DateTime=0
DateTime::Duration=0
DateTime::Format::Duration::ISO8601=0

[Prereqs / DevelopX_spec]
-phase=develop
-relationship=x_spec
Rinci=1.1.90

lib/App/durseq.pm  view on Meta::CPAN

This utility is similar to Perl script <prog:dateseq>, except that it generates
a sequence of durations instead of dates.

_
    args_rels => {
    },
    args => {
        from => {
            summary => 'Starting duration',
            schema => ['duration*', {
                'x.perl.coerce_to' => 'DateTime::Duration',
                'x.perl.coerce_rules' => ['From_str::iso8601'],
            }],
            pos => 0,
        },
        to => {
            summary => 'Ending duration, if not specified will generate an infinite* stream of durations',
            schema => ['duration*', {
                'x.perl.coerce_to' => 'DateTime::Duration',
                'x.perl.coerce_rules' => ['From_str::iso8601'],
            }],
            pos => 1,
        },
        increment => {
            summary => 'Increment, default is one day (P1D)',
            schema => ['duration*', {
                'x.perl.coerce_to' => 'DateTime::Duration',
                'x.perl.coerce_rules' => ['From_str::iso8601'],
            }],
            cmdline_aliases => {i=>{}},
            pos => 2,
        },
        reverse => {
            summary => 'Decrement instead of increment',
            schema => 'true*',
            cmdline_aliases => {r=>{}},
        },

lib/App/durseq.pm  view on Meta::CPAN

        #    summary => 'Add a header row',
        #    schema => 'str*',
        #},
        limit => {
            summary => 'Only generate a certain amount of items',
            schema => ['int*', min=>1],
            cmdline_aliases => {n=>{}},
        },

        format_class => {
            summary => 'Use a DateTime::Format::Duration::* class for formatting',
            schema => ['perl::modname'],
            default => 'ISO8601',
            tags => ['category:formatting'],
            completion => sub {
                require Complete::Module;
                my %args = @_;
                Complete::Module::complete_module(
                    word => $args{word}, ns_prefix => 'DateTime::Format::Duration');
            },
            description => <<'_',

By default, "ISO8601" (<pm:DateTime::Format::Duration::ISO8601>) is used.

_
        },
        format_class_attrs => {
            summary => 'Arguments to pass to constructor of DateTime::Format::* class',
            schema => ['hash'],
            tags => ['category:formatting'],
        },
    },
    examples => [
        {
            summary => 'Generate "infinite" durations from zero (then P1D, P2D, ...)',
            src => '[[prog]]',
            src_plang => 'bash',
            test => 0,

lib/App/durseq.pm  view on Meta::CPAN

        #},
        #{
        #    summary => 'Use with fsql',
        #    src => q{[[prog]] 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'},
        #    src_plang => 'bash',
        #    'x.doc.show_result' => 0,
        #},
    ],
};
sub durseq {
    require DateTime;
    require DateTime::Duration;
    require DateTime::Format::Duration::ISO8601;

    my %args = @_;

    my $base_dt = DateTime->now;

    $args{from} //= DateTime::Duration->new(days=>0);
    $args{increment} //= DateTime::Duration->new(days=>1);
    my $reverse = $args{reverse};

    my $cl = $args{format_class} // "ISO8601";
    $cl = "DateTime::Format::Duration::$cl";
    (my $cl_pm = "$cl.pm") =~ s!::!/!g;
    require $cl_pm;
    my $attrs = $args{format_class_attrs} // {};
    my $formatter = $cl->new(%$attrs);

    if (defined $args{to} || defined $args{limit}) {
        my @res;
        #push @res, $args{header} if $args{header};
        my $dtdur = $args{from}->clone;
        while (1) {
            if (defined $args{to}) {
                last if !$reverse && DateTime::Duration->compare($dtdur, $args{to}, $base_dt) > 0;
                last if  $reverse && DateTime::Duration->compare($dtdur, $args{to}, $base_dt) < 0;
            }
            push @res, $formatter->format_duration($dtdur);
            last if defined($args{limit}) && @res >= $args{limit};
            $dtdur = $reverse ? $dtdur - $args{increment} : $dtdur + $args{increment};
        }
        return [200, "OK", \@res];
    } else {
        # stream
        my $dtdur = $args{from}->clone;
        my $j     = $args{header} ? -1 : 0;

lib/App/durseq.pm  view on Meta::CPAN

a sequence of durations instead of dates.

This function is not exported.

Arguments ('*' denotes required arguments):

=over 4

=item * B<format_class> => I<perl::modname> (default: "ISO8601")

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

By default, "ISO8601" (L<DateTime::Format::Duration::ISO8601>) is used.

=item * B<format_class_attrs> => I<hash>

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

=item * B<from> => I<duration>

Starting duration.

=item * B<increment> => I<duration>

Increment, default is one day (P1D).

=item * B<limit> => I<int>

script/durseq  view on Meta::CPAN

Ending duration, if not specified will generate an infinite* stream of durations.

=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::Duration::* class for formatting.

Default value:

 "ISO8601"

By default, "ISO8601" (<pm:DateTime::Format::Duration::ISO8601>) is used.


=back

=head2 Output options

=over

=item B<--format>=I<s>



( run in 0.324 second using v1.01-cache-2.11-cpan-05444aca049 )