Author: rblasch
Date: Sat Aug 9 05:01:14 2008
New Revision: 30140
Modified:
trunk/config/gen/platform/win32/time.c
trunk/t/op/time.t
Log:
[win32] Adjust Parrot_floatval_time to standard epoch time.
Modified: trunk/config/gen/platform/win32/time.c
==============================================================================
--- trunk/config/gen/platform/win32/time.c (original)
+++ trunk/config/gen/platform/win32/time.c Sat Aug 9 05:01:14 2008
@@ -61,7 +61,8 @@
Parrot_floatval_time(void)
{
SYSTEMTIME sysTime;
- FILETIME fileTime; /* 100ns == 1 */
+ /* 100 ns ticks since 1601-01-01 00:00:00 */
+ FILETIME fileTime;
LARGE_INTEGER i;
GetSystemTime(&sysTime);
@@ -69,7 +70,12 @@
/* Documented as the way to get a 64 bit from a FILETIME. */
memcpy(&i, &fileTime, sizeof (LARGE_INTEGER));
- return (FLOATVAL)i.QuadPart / 10000000.0; /*1e7 */
+ /* FILETIME uses 100ns steps since 1601-01-01 00:00:00 as epoch.
+ * We'd like 1 second steps since 1970-01-01 00:00:00.
+ * To get there, divide by 10,000,000 to get from 100ns steps to seconds.
+ * Then subtract the seconds between 1601 and 1970, i.e. 11,644,473,600.
+ */
+ return (FLOATVAL)i.QuadPart / 10000000.0 - 11644473600.0;
}
Modified: trunk/t/op/time.t
==============================================================================
--- trunk/t/op/time.t (original)
+++ trunk/t/op/time.t Sat Aug 9 05:01:14 2008
@@ -6,7 +6,7 @@
use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More;
-use Parrot::Test tests => 6;
+use Parrot::Test tests => 7;
=head1 NAME
@@ -63,9 +63,6 @@
ok, (now>before) timelords need not apply
OUTPUT
-SKIP: {
- skip 'failling on win32' => 1 if $^O =~ m/win32/i;
-
pasm_output_is( <<CODE, <<OUTPUT, "sleep" );
print "start\\n"
@@ -88,8 +85,6 @@
done
OUTPUT
-}
-
pasm_error_output_like( <<CODE, <<OUT , "sleep" );
sleep -1
end
@@ -122,6 +117,35 @@
.end
CODE
+pir_output_is(<<'CODE', <<OUTPUT, "time(FLOATVAL) vs time(INTVAL)");
+.sub main :main
+ .local int time_int
+ time time_int
+
+ .local num time_float
+ time time_float
+
+ # check if time_float is within [time_int - 5;time_int + 5]
+ .local int time_int_lower
+ time_int_lower = time_int - 5
+ if time_float < time_int_lower goto FAIL
+ .local int time_int_upper
+ time_int_upper = time_int + 5
+ if time_float > time_int_upper goto FAIL
+
+ print "ok\n"
+ goto END
+
+FAIL: print "not ok\n"
+ goto END
+
+END:
+.end
+CODE
+ok
+OUTPUT
+
+
# Local Variables:
# mode: cperl
# cperl-indent-level: 4