blob: a90d431a8d8d122034fe225ac120787f8f26700b (
plain)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# Mail::Field::Date
#
# Copyright (c) 1997 Graham Barr <gbarr@pobox.com>. All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# An example of a Mail::Field::* class
package Mail::Field::Date;
use strict;
use Mail::Field ();
use vars qw(@ISA $VERSION);
use Date::Format qw(time2str);
use Date::Parse qw(str2time);
@ISA = qw(Mail::Field);
$VERSION = do { my @r=(q$Revision$=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
bless([])->register('Date');
sub set
{
my $self = shift;
my $arg = @_ == 1 ? shift : { @_ };
my $s;
foreach $s (qw(Time TimeStr))
{
if(exists $arg->{$s}) { $self->{$s} = $arg->{$s} }
else { delete $self->{$s} }
}
$self;
}
sub parse
{
my $self = shift;
delete $self->{Time};
$self->{TimeStr} = shift;
$self;
}
sub time
{
my $self = shift;
if(@_)
{
delete $self->{TimeStr};
return $self->{Time} = shift;
}
return $self->{Time}
if exists $self->{Time};
$self->{Time} = str2time($self->{TimeStr});
}
sub stringify
{
my $self = shift;
return $self->{TimeStr}
if exists $self->{TimeStr};
time2str("%a, %e %b %T %Y %z", $self->time);
}
sub reformat
{
my $self = shift;
$self->time($self->time);
$self->stringify;
}
1;
|