File: 05-format.t

package info (click to toggle)
libdate-extract-perl 0.07-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 284 kB
  • sloc: perl: 343; makefile: 2
file content (24 lines) | stat: -rw-r--r-- 730 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use strict;
use warnings;
use Test::More tests => 3;
use Test::MockTime::HiRes 'set_fixed_time';
use Date::Extract;

# a Thursday. The time I wrote this line of code, in fact (in UTC)
set_fixed_time('2007-11-16T02:48:52Z');

my $in = "Today I see a boat. Tomorrow I'll see another. Yesterday I swam.";

my $parser;

$parser = Date::Extract->new(format => 'DateTime');
my $dt = $parser->extract($in);
is($dt->ymd, '2007-11-16', 'default: returns DateTime object');

$parser = Date::Extract->new(format => 'verbatim');
my $verbatim = $parser->extract($in);
is($verbatim, 'Today', 'returns verbatim text');

$parser = Date::Extract->new(format => 'epoch');
my $epoch = $parser->extract($in);
is($epoch, 1195171200, 'returns epoch');