File Coverage

blib/lib/Rose/HTML/Form/Field/Date.pm
Criterion Covered Total %
statement 13 13 100.0
branch 3 4 75.0
condition 2 6 33.3
subroutine 4 4 100.0
pod 1 2 50.0
total 23 29 79.3


line stmt bran cond sub pod time code
1             package Rose::HTML::Form::Field::Date;
2              
3 2     2   670234 use strict;
  2         13  
  2         66  
4              
5 2     2   13 use base 'Rose::HTML::Form::Field::DateTime';
  2         5  
  2         1092  
6              
7             our $VERSION = '0.606';
8              
9             sub inflate_value
10             {
11 9     9 1 22 my($self, $date) = @_;
12 9 50 33     50 return undef unless(ref $date || (defined $date && length $date));
      33        
13 9         22 $date = $self->date_parser->parse_datetime($date);
14 9 100       2054 return $date unless(UNIVERSAL::isa($date, 'DateTime'));
15 4         17 $date->set(hour => 0, minute => 0, second => 0, nanosecond => 0);
16 4         2032 return $date;
17             }
18              
19 1     1 0 11 sub init_output_format { '%Y-%m-%d' }
20              
21             1;
22              
23             __END__
24              
25             =head1 NAME
26              
27             Rose::HTML::Form::Field::Date - Text field that inflates valid dates into L<DateTime> objects.
28              
29             =head1 SYNOPSIS
30              
31             $field =
32             Rose::HTML::Form::Field::Date->new(
33             label => 'Date',
34             name => 'date',
35             default => '12/31/2002');
36              
37             print $field->internal_value; # "2002-12-31T00:00:00"
38             print $field->output_value; # "2002-12-31"
39              
40             $field->input_value('blah');
41              
42             # "Could not parse date: blah"
43             $field->validate or warn $field->error;
44              
45             $field->input_value('4/30/1980');
46              
47             $dt = $field->internal_value; # DateTime object
48              
49             print $dt->day_name; # Wednesday
50              
51             print $field->html;
52             ...
53              
54             =head1 DESCRIPTION
55              
56             L<Rose::HTML::Form::Field::Date> is a subclass of L<Rose::HTML::Form::Field::DateTime> that handles dates, but not times. (The time is always forced to be 00:00:00.) Valid input is converted to the format "YYYY-MM-DD" on output.
57              
58             See the L<Rose::HTML::Form::Field::DateTime> documetation for more information.
59              
60             =head1 AUTHOR
61              
62             John C. Siracusa (siracusa@gmail.com)
63              
64             =head1 LICENSE
65              
66             Copyright (c) 2010 by John C. Siracusa. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.