File: date.t

package info (click to toggle)
spamassassin 3.4.0-6
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 8,296 kB
  • ctags: 2,968
  • sloc: perl: 54,007; ansic: 3,397; sh: 590; makefile: 195; sql: 176; python: 17
file content (55 lines) | stat: -rwxr-xr-x 1,480 bytes parent folder | download | duplicates (6)
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
#!/usr/bin/perl -w

BEGIN {
  if (-e 't/test_dir') { # if we are running "t/rule_tests.t", kluge around ...
    chdir 't';
  }

  if (-e 'test_dir') {            # running from test directory, not ..
    unshift(@INC, '../blib/lib');
  }
}

my $prefix = '.';
if (-e 'test_dir') {            # running from test directory, not ..
  $prefix = '..';
}

use strict;
use Test;
use Mail::SpamAssassin;
use Mail::SpamAssassin::Util;

plan tests => 14;

sub try {
  my ($data, $want) = @_;

  my $time = Mail::SpamAssassin::Util::parse_rfc822_date($data);
  if (!$time) {
    return 0;
  }
  if ($want && $want ne $time) {
    print "time mismatch: $data -> $time but wanted $want\n";
    return 0;
  }
  return 1;
}

# good dates
ok(try('Mon, 31 Oct 2005 18:44:29 -0800', 1130813069));
ok(try('Wed, 28 Sep 2005 16:24:49 +0800 (CST)',	1127895889));
ok(try('Tue, 25 Apr 2006 02:15:29 -0700', 1145956529));
ok(try('Sun, 8 Jan 2006 13:12:04 +0100', 1136722324));
ok(try('Mon, 8 May 2006 15:49:45 -0700', 1147128585));
ok(try('Sat, 14 Jan 2037 21:03:03 -0000', 2115579783));

# invalid dates
ok(try('Mon, 20 Sep 2004 21:43:60 -0700 (PDT)'));
ok(try('Mon, 20 Sep 2004 23:60:57 -0700 (PDT)'));
ok(try('Mon, 20 Sep 2004 24:43:57 -0700 (PDT)'));
ok(try('Mon, 31 Sep 2004 21:43:57 -0700 (PDT)'));
ok(try('Mon, 32 Dec 2004 21:43:57 -0700 (PDT)'));
ok(try('Mon, 32 Jan 2004 21:43:57 -0700 (PDT)'));
ok(try('Sun, 29 Feb 2006 21:43:57 -0800 (PST)'));
ok(try('Sun, 30 Feb 2006 21:43:57 -0800 (PST)'));