Create fields are fixed again. Also fixed: ChooseMany when tryingto remove the last...
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort / Field / DateTime.pm
1 package Reaction::UI::ViewPort::Field::DateTime;
2
3 use Scalar::Util 'blessed';
4 use Reaction::Class;
5 use Reaction::Types::DateTime;
6 use aliased 'Reaction::UI::ViewPort::Field';
7
8 class DateTime is Field, which {
9   has '+value' => (isa => 'DateTime');
10
11   has value_string_default_format => (
12     isa => 'Str', is => 'rw', required => 1, default => sub { "%F %H:%M:%S" }
13   );
14
15   implements _build_value_string => as {
16     my $self = shift;
17     # XXX
18     #<mst> aha, I know why the fucker's lazy
19     #<mst> it's because if value's calculated
20     #<mst> it needs to be possible to clear it
21     #<mst> eval { $self->value } ... is probably the best solution atm
22     my $value = $self->value;
23     return '' unless blessed $value;
24     my $format = $self->value_string_default_format;
25     return $value->strftime($format);
26   };
27
28   implements _empty_value => as { undef };
29
30 };
31
32 1;