work in progress, listview still broken
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort / Field / Mutable / DateTime.pm
CommitLineData
ddccc6a2 1package Reaction::UI::ViewPort::Field::Mutable::DateTime;
2
3use Reaction::Class;
4use Time::ParseDate;
5use DateTime;
6
c8fbb8ad 7class 'Reaction::UI::ViewPort::Field::Mutable::DateTime', is 'Reaction::UI::ViewPort::Field::DateTime', which {
ddccc6a2 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
c8fbb8ad 28 around accept_events => sub { ('value_string', shift->(@_)) };
ddccc6a2 29
30};
31
321;
33
34
35=head1 NAME
36
37Reaction::UI::ViewPort::Field::DateTime
38
39=head1 DESCRIPTION
40
41=head1 METHODS
42
43=head2 value_string
44
45Accessor for the string representation of the DateTime object.
46
47=head2 value_string_default_format
48
49By 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
59See L<Reaction::Class> for authors.
60
61=head1 LICENSE
62
63See L<Reaction::Class> for the license.
64
65=cut