revert r620
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort / Field / Mutable / DateTime.pm
1 package Reaction::UI::ViewPort::Field::Mutable::DateTime;
2
3 use Reaction::Class;
4 use Time::ParseDate;
5 use DateTime;
6
7 class 'Reaction::UI::ViewPort::Field::Mutable::DateTime',
8   is 'Reaction::UI::ViewPort::Field::DateTime', which {
9
10   does 'Reaction::UI::ViewPort::Field::Role::Mutable::Simple';
11
12   implements adopt_value_string => as {
13     my ($self) = @_;
14     my $value = $self->value_string;
15     my ($epoch) = Time::ParseDate::parsedate($value);
16     if (defined $epoch) {
17       my $dt = 'DateTime'->from_epoch( epoch => $epoch );
18       $self->value($dt);
19     } else {
20       $self->message("Could not parse date or time");
21     }
22   };
23
24 };
25
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