aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Reaction/UI/ViewPort/Field/Mutable/DateTime.pm
blob: 27181f5369032541653d32d8ce252c151dc3e74b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package Reaction::UI::ViewPort::Field::Mutable::DateTime;

use Reaction::Class;
use Time::ParseDate;
use DateTime;

use namespace::clean -except => [ qw(meta) ];
extends 'Reaction::UI::ViewPort::Field::DateTime';

with 'Reaction::UI::ViewPort::Field::Role::Mutable::Simple';
sub adopt_value_string {
  my ($self) = @_;
  my $value = $self->value_string;
  my ($epoch) = Time::ParseDate::parsedate($value);
  if (defined $epoch) {
    my $dt = 'DateTime'->from_epoch( epoch => $epoch );
    $self->value($dt);
  } else {
    $self->value($self->value_string);
  }
};

__PACKAGE__->meta->make_immutable;


1;


=head1 NAME

Reaction::UI::ViewPort::Field::DateTime

=head1 DESCRIPTION

=head1 METHODS

=head2 value_string

Accessor for the string representation of the DateTime object.

=head2 value_string_default_format

By default it is set to "%F %H:%M:%S".

=head1 SEE ALSO

=head2 L<DateTime>

=head2 L<Reaction::UI::ViewPort::Field>

=head1 AUTHORS

See L<Reaction::Class> for authors.

=head1 LICENSE

See L<Reaction::Class> for the license.

=cut