File: Date.pm

package info (click to toggle)
otrs 1%3A1.3.3p01-4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 15,564 kB
  • ctags: 3,367
  • sloc: perl: 66,003; sql: 4,703; sh: 1,151; xml: 727; makefile: 25; php: 16
file content (80 lines) | stat: -rw-r--r-- 1,214 bytes parent folder | download | duplicates (4)
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 = '1.60';

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;