1 # This module is part of da_reference, and is released
2 # under the terms of the GPL version 2, or any later version. See the
3 # file README and COPYING for more information.
4 # Copyright 2003 by Don Armstrong <don@donarmstrong.com>.
5 # $Id: Date.pm 42 2009-03-20 06:29:46Z don $
7 package Reference::Field::Date;
27 use vars qw($REVISION $DEBUG);
30 use Params::Validate qw(:types validate_with);
35 ($REVISION) = q$LastChangedRevision: 42 $ =~ /\$LastChangedRevision:\s+([^\s+])/;
36 $DEBUG = 0 unless defined $DEBUG;
51 if (scalar(@_) == 1) {
52 $params{date} = shift;
53 $params{output} = 'scalar';
56 %params = validate_with(params => \@_,
57 spec => {date => {type => ARRAYREF|SCALAR|HASHREF|UNDEF,
60 day => {type => SCALAR|UNDEF,
63 year => {type => SCALAR|UNDEF,
66 month => {type => SCALAR|UNDEF,
69 output => {default => 'scalar',
75 # Update author according to the passed information
76 if (defined $params{day} or defined $params{year} or defined $params{month}) {
77 $self->{reference}->{date}->{day} = $params{day} if defined $params{day};
78 $self->{reference}->{date}->{year} = $params{year} if defined $params{year};
79 $self->{reference}->{date}->{month} = $params{month} if defined $params{month};
81 elsif (defined $params{date}) {
82 $self->{reference}->{date} = {day => undef,
86 my $date = ParseDate($params{date});
87 $self->{reference}->{date}->{unix} = $date;
88 ($self->{reference}->{date}->{day},
89 $self->{reference}->{date}->{year},
90 $self->{reference}->{date}->{month}) = UnixDate($date,qw(%e %Y %m));
93 local $_ = $params{output};
95 return UnixDate($self->{reference}->{date}->{unix},'%B %e %Y') if defined $self->{reference}->{date}->{unix};
96 return join(' ',$self->{reference}->{date}->{day},$self->{reference}->{date}->{year},$self->{reference}->{date}->{month});
99 return UnixDate($self->{reference}->{date}->{unix},'%Y') if defined $self->{reference}->{date}->{unix};
100 return $self->{reference}->{date}->{year};
103 return UnixDate($self->{reference}->{date}->{unix},'%B %e %Y') if defined $self->{reference}->{date}->{unix};
104 return join(' ',$self->{reference}->{date}->{day},$self->{reference}->{date}->{year},$self->{reference}->{date}->{month});
112 Returns the year associated with the date field
121 return $self->{reference}->{date}->{year};
128 Returns the day associated with the date field
135 return $self->{reference}->{date}->{day};
142 Returns the month associated with the date field
149 return $self->{reference}->{date}->{month};
156 $self->{reference}->{date} = {month => undef,