choosemany is still broken (not applying changes) but everything else is looking...
[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   around accept_events => sub { ('value_string', shift->(@_)) };
30
31 };
32
33 1;
34
35
36 =head1 NAME
37
38 Reaction::UI::ViewPort::Field::DateTime
39
40 =head1 DESCRIPTION
41
42 =head1 METHODS
43
44 =head2 value_string
45
46 Accessor for the string representation of the DateTime object.
47
48 =head2 value_string_default_format
49
50 By default it is set to "%F %H:%M:%S".
51
52 =head1 SEE ALSO
53
54 =head2 L<DateTime>
55
56 =head2 L<Reaction::UI::ViewPort::Field>
57
58 =head1 AUTHORS
59
60 See L<Reaction::Class> for authors.
61
62 =head1 LICENSE
63
64 See L<Reaction::Class> for the license.
65
66 =cut