Debian Codegraph @

t/25-date-format-bug.t

raw
1 use strict;
2 use warnings;
3 use Test::More;
4
5 use DateTime;
6 use XML::XPath;
7
8 use XML::Feed;
9 use XML::Feed::Entry;
10
11 # https://rt.cpan.org/Public/Bug/Display.html?id=48337
12 # https://rt.cpan.org/Public/Bug/Display.html?id=103405
13
14 my $feed = XML::Feed->new('Atom');
15
16 # Bugs are with "floating" DateTime, so explicitly set time_zone.
17 # DateTime->new() defaults to "floating" (usually) but DateTime->now()
18 # defaults to "UTC".
19 my $dt = DateTime->now(time_zone => 'floating');
20
21 $feed->title("My Atom feed");
22 $feed->link("http://www.example.com");
23 $feed->author("Author");
24 $feed->updated($dt);
25 $feed->id("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344eaa6a");
26
27 my $entry = XML::Feed::Entry->new('Atom');
28 $entry->title("An important event");
29 $entry->author("Important author");
30 $entry->content("A very interesting event happened.");
31
32 $entry->issued($dt);
33 $entry->updated($dt);
34 $entry->id("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a");
35
36 $feed->add_entry($entry);
37
38 my $xp = XML::XPath->new(xml => $feed->as_xml);
39 my $rfc3339 = qr!<updated>\d{4}-\d{2}-\d{2}T.+Z.*</updated>!;
40 like $xp->findnodes_as_string('/feed/updated'), $rfc3339;
41 like $xp->findnodes_as_string('/feed/entry/updated'), $rfc3339;
42
43 done_testing();