1 package Reaction::UI::ViewPort::Field::DateTime;
4 use Reaction::Types::DateTime;
5 use Time::ParseDate ();
7 class DateTime is 'Reaction::UI::ViewPort::Field', which {
9 has '+value' => (isa => 'DateTime');
11 #has '+layout' => (default => 'dt_textfield');
14 isa => 'Str', is => 'rw', lazy_build => 1,
15 trigger_adopt('value_string')
18 has value_string_default_format => (
19 isa => 'Str', is => 'rw', required => 1, default => sub { "%F %H:%M:%S" }
22 implements _build_value_string => as {
26 #<mst> aha, I know why the fucker's lazy
27 #<mst> it's because if value's calculated
28 #<mst> it needs to be possible to clear it
29 #<mst> eval { $self->value } ... is probably the best solution atm
30 my $value = eval { $self->value };
31 return '' unless $self->has_value;
32 my $format = $self->value_string_default_format;
33 return $value->strftime($format) if $value;
37 implements adopt_value_string => as {
39 my $value = $self->value_string;
40 my ($epoch) = Time::ParseDate::parsedate($value, UK => 1);
42 my $dt = 'DateTime'->from_epoch( epoch => $epoch );
45 $self->message("Could not parse date or time");
51 override accept_events => sub {
52 ('value_string', super());
61 Reaction::UI::ViewPort::Field::DateTime
69 Accessor for the string representation of the DateTime object.
71 =head2 value_string_default_format
73 By default it is set to "%F %H:%M:%S".
79 =head2 L<Reaction::UI::ViewPort::Field>
83 See L<Reaction::Class> for authors.
87 See L<Reaction::Class> for the license.