]> Sergey Matveev's repositories - public-inbox.git/blob - t/time.t
msgtime: parse 3-digit years properly
[public-inbox.git] / t / time.t
1 # Copyright (C) 2018 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3 use strict;
4 use warnings;
5 use Test::More;
6 use_ok 'PublicInbox::MIME';
7 use PublicInbox::MsgTime qw(msg_datestamp);
8 my $mime = PublicInbox::MIME->create(
9         header => [
10                 From => 'a@example.com',
11                 To => 'test@example.com',
12                 Subject => 'this is a subject',
13                 'Message-ID' => '<a-mid@b>',
14                 Date => 'Fri, 02 Oct 93 00:00:00 +0000',
15         ],
16         body => "hello world\n",
17 );
18
19 my $ts = msg_datestamp($mime->header_obj);
20 use POSIX qw(strftime);
21 is(strftime('%Y-%m-%d %H:%M:%S', gmtime($ts)), '1993-10-02 00:00:00',
22         'got expected date with 2 digit year');
23 $mime->header_set(Date => 'Fri, 02 Oct 101 01:02:03 +0000');
24 $ts = msg_datestamp($mime->header_obj);
25 is(strftime('%Y-%m-%d %H:%M:%S', gmtime($ts)), '2001-10-02 01:02:03',
26         'got expected date with 3 digit year');
27
28 done_testing();