File: README

package info (click to toggle)
libtypes-datetime-perl 0.002-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 180 kB
  • ctags: 7
  • sloc: perl: 109; makefile: 13; sh: 4
file content (169 lines) | stat: -rw-r--r-- 5,349 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
NAME
    Types::DateTime - type constraints and coercions for datetime objects

SYNOPSIS
       package FroobleGala;
   
       use Moose;
       use Types::DateTime -all;
   
       has start_date => (
          is      => 'ro',
          isa     => DateTimeUTC->plus_coercions( Format['ISO8601'] ),
          coerce  => 1,
       );

DESCRIPTION
    Types::DateTime is a type constraint library suitable for use with
    Moo/Moose attributes, Kavorka sub signatures, and so forth.

  Types
    This module provides some type constraints broadly compatible with those
    provided by MooseX::Types::DateTime, plus a couple of extra type
    constraints.

    `DateTime`
        A class type for DateTime. Coercions from:

        from `Num`
            Uses "from_epoch" in DateTime. Floating values will be used for
            sub-second precision, see DateTime for details.

        from `HashRef`
            Calls "new" in DateTime or "from_epoch" in DateTime as
            appropriate, passing the hash as arguments.

        from `Now`
            Uses "now" in DateTime.

        from `InstanceOf['DateTime::Tiny']`
            Inflated using "DateTime" in DateTime::Tiny.

    `Duration`
        A class type for DateTime::Duration. Coercions from:

        from `Num`
            Uses "new" in DateTime::Duration and passes the number as the
            `seconds` argument.

        from `HashRef`
            Calls "new" in DateTime::Duration with the hash entries as
            arguments.

    `Locale`
        A class type for DateTime::Locale. Coercions from:

        from `Str`
            The string is treated as a language tag (e.g. `en` or `he_IL`) and
            given to "load" in DateTime::Locale.

        from `InstanceOf['Locale::Maketext']`
            The `Locale::Maketext/language_tag` attribute will be used with
            "load" in DateTime::Locale.

    `TimeZone`
        A class type for DateTime::TimeZone. Coercions from:

        from `Str`
            Treated as a time zone name or offset. See "USAGE" in
            DateTime::TimeZone for more details on the allowed values.

            Delegates to "new" in DateTime::TimeZone with the string as the
            `name` argument.

    `Now`
        Type constraint with only one allowed value, the string "now".

        This is exported for compatibility with MooseX::Types::DateTime, which
        exports such a constraint, even though it is not documented.

    `DateTimeWithZone`
        A subtype of `DateTime` for objects with a defined (non-floating) time
        zone.

        This type constraint inherits its coercions from `DateTime`.

    `DateTimeWithZone[`a]`
        The `DateTimeWithZone` type constraint may be parameterized with a
        DateTime::TimeZone object, or a string that can be coerced into one.

           has start_date => (
              is      => 'ro',
              isa     => DateTimeWithZone['Europe/London'],
              coerce  => 1,
           );

        This type constraint inherits its coercions from `DateTime`, and will
        additionally call "set_time_zone" in DateTime to shift objects into
        the correct timezone.

    `DateTimeUTC`
        Shortcut for `DateTimeWithZone["UTC"]`.

  Named Coercions
    It is hoped that Type::Tiny will help avoid the proliferation of modules
    like MooseX::Types::DateTimeX, MooseX::Types::DateTime::ButMaintained, and
    MooseX::Types::DateTime::MoreCoercions. It makes it very easy to add
    coercions to a type constraint at the point of use:

       has start_date => (
          is      => 'ro',
          isa     => DateTime->plus_coercions(
             InstanceOf['MyApp::DT'] => sub { $_->to_DateTime }
          ),
          coerce  => 1,
       );

    Even easier, this module exports some named coercions.

    `Format[`a]`
        May be passed an object providing a `parse_datetime` method, or a
        class name from the `DateTime::Format::` namespace (upon which `new`
        will be called).

        For example:

           DateTime->plus_coercions( Format['ISO8601'] )

        Or:

           DateTimeUTC->plus_coercions(
              Format[
                 DateTime::Format::Natural->new(lang => 'en')
              ]
           )

    `Strftime[`a]`
        A pattern for serializing a DateTime object into a string using
        "strftime" in DateTime.

           Str->plus_coercions( Strftime['%a %e %b %Y'] );

    `ToISO8601`
        A coercion for serializing a DateTime object into a string using
        "iso8601" in DateTime.

           Str->plus_coercions( ToISO8601 );

BUGS
    Please report any bugs to
    <http://rt.cpan.org/Dist/Display.html?Queue=Types-DateTime>.

SEE ALSO
    MooseX::Types::DateTime, Type::Tiny::Manual, DateTime, DateTime::Duration,
    DateTime::Locale, DateTime::TimeZone.

AUTHOR
    Toby Inkster <tobyink@cpan.org>.

COPYRIGHT AND LICENCE
    This software is copyright (c) 2014, 2017 by Toby Inkster.

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

DISCLAIMER OF WARRANTIES
    THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
    WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
    MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.