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              
2             use strict;
3 2     2   541303  
  2         12  
  2         59  
4             use base 'Rose::HTML::Form::Field::DateTime';
5 2     2   9  
  2         4  
  2         897  
6             our $VERSION = '0.606';
7              
8             {
9             my($self, $date) = @_;
10             return undef unless(ref $date || (defined $date && length $date));
11 9     9 1 16 $date = $self->date_parser->parse_datetime($date);
12 9 50 33     41 return $date unless(UNIVERSAL::isa($date, 'DateTime'));
      33        
13 9         20 $date->set(hour => 0, minute => 0, second => 0, nanosecond => 0);
14 9 100       1626 return $date;
15 4         13 }
16 4         1656  
17              
18             1;
19 1     1 0 10  
20              
21             =head1 NAME
22              
23             Rose::HTML::Form::Field::Date - Text field that inflates valid dates into L<DateTime> objects.
24              
25             =head1 SYNOPSIS
26              
27             $field =
28             Rose::HTML::Form::Field::Date->new(
29             label => 'Date',
30             name => 'date',
31             default => '12/31/2002');
32              
33             print $field->internal_value; # "2002-12-31T00:00:00"
34             print $field->output_value; # "2002-12-31"
35              
36             $field->input_value('blah');
37              
38             # "Could not parse date: blah"
39             $field->validate or warn $field->error;
40              
41             $field->input_value('4/30/1980');
42              
43             $dt = $field->internal_value; # DateTime object
44              
45             print $dt->day_name; # Wednesday
46              
47             print $field->html;
48             ...
49              
50             =head1 DESCRIPTION
51              
52             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.
53              
54             See the L<Rose::HTML::Form::Field::DateTime> documetation for more information.
55              
56             =head1 AUTHOR
57              
58             John C. Siracusa (siracusa@gmail.com)
59              
60             =head1 LICENSE
61              
62             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.