xref: /openbsd-src/gnu/usr.bin/perl/cpan/Time-Piece/t/10overload.t (revision de8cc8edbc71bd3e3bc7fbffa27ba0e564c37d8b)
1use strict;
2use warnings;
3use Time::Piece;
4use Test::More;
5
6eval 'use Math::BigInt';
7plan skip_all => "Math::BigInt required for testing overloaded operands" if $@;
8
9my $t = Time::Piece->gmtime(315532800); # 00:00:00 1/1/1980
10isa_ok $t, 'Time::Piece';
11is $t->cdate, 'Tue Jan  1 00:00:00 1980', 'got expected gmtime with int secs';
12
13$t = Time::Piece->gmtime(Math::BigInt->new('315532800')); # 00:00:00 1/1/1980
14is $t->cdate, 'Tue Jan  1 00:00:00 1980', 'got same time with overloaded secs';
15
16
17my $big_hour = Math::BigInt->new('3600');
18
19$t = $t + $big_hour;
20is $t->cdate, 'Tue Jan  1 01:00:00 1980', 'add overloaded value';
21
22$t = $t - $big_hour;
23is $t->cdate, 'Tue Jan  1 00:00:00 1980', 'sub overloaded value';
24
25done_testing;
26