diff options
author | Tony Cook <tony@develop-help.com> | 2010-02-24 00:35:35 +1100 |
---|---|---|
committer | Tony Cook <tony@develop-help.com> | 2010-05-17 20:56:35 +1000 |
commit | 7eb4f9b7b5bb8d1dc09764c85ca57bc61f5b6f92 (patch) | |
tree | 8ced50840f5b94239b21df723ce52d2ec9a022bc | |
parent | 3a4f5623ceba62875ff92612b0be44b47382321a (diff) | |
download | perl-7eb4f9b7b5bb8d1dc09764c85ca57bc61f5b6f92.tar.gz |
use the correct format codes in warnings from gmtime/localtime
-rw-r--r-- | pp_sys.c | 10 | ||||
-rw-r--r-- | t/op/time.t | 43 |
2 files changed, 47 insertions, 6 deletions
@@ -4505,22 +4505,22 @@ PP(pp_gmtime) when = (Time64_T)now; } else { - double input = Perl_floor(POPn); + NV input = Perl_floor(POPn); when = (Time64_T)input; if (when != input) { Perl_ck_warner(aTHX_ packWARN(WARN_OVERFLOW), - "%s(%.0f) too large", opname, input); + "%s(%.0" NVff ") too large", opname, input); } } if ( TIME_LOWER_BOUND > when ) { Perl_ck_warner(aTHX_ packWARN(WARN_OVERFLOW), - "%s(%.0f) too small", opname, when); + "%s(%.0" NVff ") too small", opname, when); err = NULL; } else if( when > TIME_UPPER_BOUND ) { Perl_ck_warner(aTHX_ packWARN(WARN_OVERFLOW), - "%s(%.0f) too large", opname, when); + "%s(%.0" NVff ") too large", opname, when); err = NULL; } else { @@ -4533,7 +4533,7 @@ PP(pp_gmtime) if (err == NULL) { /* XXX %lld broken for quads */ Perl_ck_warner(aTHX_ packWARN(WARN_OVERFLOW), - "%s(%.0f) failed", opname, (double)when); + "%s(%.0" NVff ") failed", opname, when); } if (GIMME != G_ARRAY) { /* scalar context */ diff --git a/t/op/time.t b/t/op/time.t index 84eaf752f3..7db8ee89ed 100644 --- a/t/op/time.t +++ b/t/op/time.t @@ -6,7 +6,7 @@ BEGIN { require './test.pl'; } -plan tests => 62; +plan tests => 66; # These tests make sure, among other things, that we don't end up # burning tons of CPU for dates far in the future. @@ -200,3 +200,44 @@ ok(gmtime() =~ /^(Sun|Mon|Tue|Wed|Thu|Fri|Sat)[ ] $date = localtime($small_time); like $warning, qr/^localtime(.*) too small/; } + +SKIP: { #rt #73040 + # these are from the definitions of TIME_LOWER_BOUND AND TIME_UPPER_BOUND + my $smallest = -67768100567755200.0; + my $biggest = 67767976233316800.0; + + # offset to a value that will fail + my $small_time = $smallest - 200; + my $big_time = $biggest + 200; + + # check they're representable - typically means NV is + # long double + if ($small_time + 200 != $smallest + || $small_time == $smallest + || $big_time - 200 != $biggest + || $big_time == $biggest) { + skip "Can't represent test values", 4; + } + my $small_time_f = sprintf("%.0f", $small_time); + my $big_time_f = sprintf("%.0f", $big_time); + + # check the numbers in the warning are correct + my $warning; + local $SIG{__WARN__} = sub { $warning .= join "\n", @_; }; + $warning = ''; + my $date = gmtime($big_time); + like $warning, qr/^gmtime\($big_time_f\) too large/; + + $warning = ''; + $date = localtime($big_time); + like $warning, qr/^localtime\($big_time_f\) too large/; + + $warning = ''; + $date = gmtime($small_time); + like $warning, qr/^gmtime\($small_time_f\) too small/; + + $warning = ''; + $date = localtime($small_time); + like $warning, qr/^localtime\($small_time_f\) too small/; + +} |