new renamed viewports
[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';
11
12   has value_string =>
13     ( is => 'rw', isa => 'Str', lazy_build => 1, trigger_adopt('value_string') );
14
15   implements adopt_value_string => as {
16     my ($self) = @_;
17     my $value = $self->value_string;
18     my ($epoch) = Time::ParseDate::parsedate($value);
19     if (defined $epoch) {
20       my $dt = 'DateTime'->from_epoch( epoch => $epoch );
21       $self->value($dt);
22     } else {
23       $self->message("Could not parse date or time");
24       $self->clear_value;
25       $self->needs_sync(1);
26     }
27   };
28
29   override accept_events => sub {
30     ('value_string', super());
31   };
32
33 };
34
35 1;
36
37
38 =head1 NAME
39
40 Reaction::UI::ViewPort::Field::DateTime
41
42 =head1 DESCRIPTION
43
44 =head1 METHODS
45
46 =head2 value_string
47
48 Accessor for the string representation of the DateTime object.
49
50 =head2 value_string_default_format
51
52 By default it is set to "%F %H:%M:%S".
53
54 =head1 SEE ALSO
55
56 =head2 L<DateTime>
57
58 =head2 L<Reaction::UI::ViewPort::Field>
59
60 =head1 AUTHORS
61
62 See L<Reaction::Class> for authors.
63
64 =head1 LICENSE
65
66 See L<Reaction::Class> for the license.
67
68 =cut