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