Commit | Line | Data |
ddccc6a2 |
1 | package Reaction::UI::ViewPort::Field::Mutable::DateTime; |
2 | |
3 | use Reaction::Class; |
4 | use Time::ParseDate; |
5 | use DateTime; |
6 | |
81393881 |
7 | use namespace::clean -except => [ qw(meta) ]; |
8 | extends 'Reaction::UI::ViewPort::Field::DateTime'; |
9 | |
10 | with 'Reaction::UI::ViewPort::Field::Role::Mutable::Simple'; |
11 | sub adopt_value_string { |
12 | my ($self) = @_; |
13 | my $value = $self->value_string; |
14 | my ($epoch) = Time::ParseDate::parsedate($value); |
15 | if (defined $epoch) { |
16 | my $dt = 'DateTime'->from_epoch( epoch => $epoch ); |
17 | $self->value($dt); |
18 | } else { |
19 | $self->value($self->value_string); |
20 | } |
ddccc6a2 |
21 | }; |
22 | |
81393881 |
23 | __PACKAGE__->meta->make_immutable; |
24 | |
25 | |
ddccc6a2 |
26 | 1; |
27 | |
28 | |
29 | =head1 NAME |
30 | |
31 | Reaction::UI::ViewPort::Field::DateTime |
32 | |
33 | =head1 DESCRIPTION |
34 | |
35 | =head1 METHODS |
36 | |
37 | =head2 value_string |
38 | |
39 | Accessor for the string representation of the DateTime object. |
40 | |
41 | =head2 value_string_default_format |
42 | |
43 | By default it is set to "%F %H:%M:%S". |
44 | |
45 | =head1 SEE ALSO |
46 | |
47 | =head2 L<DateTime> |
48 | |
49 | =head2 L<Reaction::UI::ViewPort::Field> |
50 | |
51 | =head1 AUTHORS |
52 | |
53 | See L<Reaction::Class> for authors. |
54 | |
55 | =head1 LICENSE |
56 | |
57 | See L<Reaction::Class> for the license. |
58 | |
59 | =cut |