Re: What is a leap second

2002-11-01 Thread György 'Nog' Jeney
> On Wednesday 30 October 2002 09:12, György 'Nog' Jeney wrote:
>> >> György, could you check which other includes can be used if
>> winternl.h is absent? Else youll probably have to wait for
>> somebody which has it to compile your test.
>> >
>> > This is included in the latest platform SDK but it should also be
>> defined in ntddk.h.
>>
>> Ok, could somene rather compile this test and send its results? It
>> will be quite big...
> FWIW, RtlTimeToTimeFields() was not declared in the winternl.h included
> in the  PSDK (August 2002) I downloaded and I didn't bother to d/l the
> DDK as well... I took the prototype from Wine's winternl.h instead,
> together with the  declarations for CSHORT and TIME_FIELDS. Then bcc32
> doesn't like inline in C  code, so I just removed that; LARGE_INTEGER
> apparently has no field named "s"  in the headers that came with C++
> Builder, but s/RtlTime.s./RtlTime./g helped  for this; finally I had to
> rename WinMain() to main() as I didn't find the  command line switch to
> produce a Windows Console app :-)
> Also I loaded RtlTimeToTimeFields() from ntdll via GetProcAddress to
> avoid  rebuilding the import library.
> Anyway, output attached.
>

Thank you and Peter for compiling my test.  This just shows that our
implementation is 100% correct and that windows does ignore leap seconds.

nog.






Re: What is a leap second

2002-10-30 Thread Malte Starostik
On Wednesday 30 October 2002 09:12, György 'Nog' Jeney wrote:
> >> György, could you check which other includes can be used if winternl.h
> >> is absent? Else youll probably have to wait for somebody which has
> >> it to compile your test.
> >
> > This is included in the latest platform SDK but it should also be
> > defined in ntddk.h.
>
> Ok, could somene rather compile this test and send its results? It will be
> quite big...
FWIW, RtlTimeToTimeFields() was not declared in the winternl.h included in the 
PSDK (August 2002) I downloaded and I didn't bother to d/l the DDK as well...
I took the prototype from Wine's winternl.h instead, together with the 
declarations for CSHORT and TIME_FIELDS. Then bcc32 doesn't like inline in C 
code, so I just removed that; LARGE_INTEGER apparently has no field named "s" 
in the headers that came with C++ Builder, but s/RtlTime.s./RtlTime./g helped 
for this; finally I had to rename WinMain() to main() as I didn't find the 
command line switch to produce a Windows Console app :-)
Also I loaded RtlTimeToTimeFields() from ntdll via GetProcAddress to avoid 
rebuilding the import library.
Anyway, output attached.

HTH,
-Malte


timetest.out.bz2
Description: BZip2 compressed data


msg13139/pgp0.pgp
Description: signature


Re: What is a leap second

2002-10-30 Thread Peter Ekberg
> > with the following output on win2k.
> > 9 0 10 0 9 10
> 
> This is weird, I would have expected to get an output like: 2002 10
27 8 9 10
> with the followingo patch applied...
> 
> nog.

Eeek, sorry about that. I forgot a WINAPI in the typedef, see my new
version in the attachment...

The following output is more in line with your expectations:
2002 10 27 8 9 10

I have also attached the output of timetest2.c after some adjustments
to make it compile on my box which is missing winternl.h. (I didn't
take the time to download the SDK.)

However, I don't follow the part about appling patches. I have
compiled the code using msvc and executed the code on windows 2000.

/peda

#include 
#include 

typedef short CSHORT;
typedef struct {
	CSHORT Year;
	CSHORT Month;
	CSHORT Day;
	CSHORT Hour;
	CSHORT Minute;
	CSHORT Second;
	CSHORT Milliseconds;
	CSHORT Weekday;
} TIME_FIELDS, *PTIME_FIELDS;


typedef VOID (WINAPI *RtlTimeToTimeFieldsT)
	(PLARGE_INTEGER Time, PTIME_FIELDS TimeFields);

int
main()
{
	LARGE_INTEGER RtlTime;
	TIME_FIELDS tf;
	HINSTANCE hLib;
	RtlTimeToTimeFieldsT RtlTimeToTimeFields;

	RtlTime.LowPart = 0x20de5700;
	RtlTime.HighPart = 0x1c27d90;

	hLib = LoadLibrary("ntdll");

	RtlTimeToTimeFields = (RtlTimeToTimeFieldsT)
		GetProcAddress(hLib, "RtlTimeToTimeFields");

	RtlTimeToTimeFields(&RtlTime, &tf);

	FreeLibrary(hLib);

	printf("%d %d %d %d %d %d\n",
		tf.Year, tf.Month, tf.Day,
		tf.Hour, tf.Minute, tf.Second);
	return 0;
}


#include 
#include 

typedef short CSHORT;
typedef struct {
	CSHORT Year;
	CSHORT Month;
	CSHORT Day;
	CSHORT Hour;
	CSHORT Minute;
	CSHORT Second;
	CSHORT Milliseconds;
	CSHORT Weekday;
} TIME_FIELDS, *PTIME_FIELDS;


typedef VOID (WINAPI *RtlTimeToTimeFieldsT)(PLARGE_INTEGER Time, PTIME_FIELDS TimeFields);

#define testtime(HighTime, LowTime) \
	RtlTime.HighPart = HighTime; \
	RtlTime.LowPart = LowTime; \
	RtlTimeToTimeFields(&RtlTime, &tf); \
	printf("%04d %02d %02d %02d %02d %02d\n", tf.Year, tf.Month, tf.Day,\
		tf.Hour, tf.Minute, tf.Second);

/* The year to which to test */
#define TargetYear 

/* Taken from dlls/ntdll/time.c */
#define EPOCHYEAR  1601
#define TICKSPERSEC1000
#define SECSPERDAY 86400
#define MONSPERYEAR12
static const int MonthLengths[2][MONSPERYEAR] =
{
	{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
	{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
};

int IsLeapYear(int Year)
{
	return Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) ? 1 : 0;
}

int
main()
{
	int Month, Year;
	UINT64 time = 0, tmp;

	LARGE_INTEGER RtlTime;
	TIME_FIELDS tf;
	HINSTANCE hLib;
	RtlTimeToTimeFieldsT RtlTimeToTimeFields;

	hLib = LoadLibrary("ntdll");

	RtlTimeToTimeFields =
		(RtlTimeToTimeFieldsT)GetProcAddress
			(hLib, "RtlTimeToTimeFields");

	for(Year = 0; Year <= (TargetYear - EPOCHYEAR); Year++) {
		for(Month = 0; Month < MONSPERYEAR; Month++) {
			tmp = MonthLengths[IsLeapYear(Year + EPOCHYEAR)][Month] * SECSPERDAY;
			tmp *= TICKSPERSEC;
			time += tmp;
			testtime(time >> 32, (time & 0x));
		}
	}

	FreeLibrary(hLib);

	return 0;
}




timetest2.zip
Description: Zip archive


Re: What is a leap second

2002-10-30 Thread Peter Ekberg
Hello!

I compiled the following using msvc:

--8<---
#include 
#include 

typedef short CSHORT;
typedef struct {
CSHORT Year;
CSHORT Month;
CSHORT Day;
CSHORT Hour;
CSHORT Minute;
CSHORT Second;
CSHORT Milliseconds;
CSHORT Weekday;
} TIME_FIELDS, *PTIME_FIELDS;


typedef VOID (*RtlTimeToTimeFieldsT)
(PLARGE_INTEGER Time, PTIME_FIELDS TimeFields);

int
main()
{
LARGE_INTEGER RtlTime;
TIME_FIELDS tf;
HINSTANCE hLib;
RtlTimeToTimeFieldsT RtlTimeToTimeFields;

RtlTime.LowPart = 0x20de5700;
RtlTime.HighPart = 0x1c27d90;

hLib = LoadLibrary("ntdll");

RtlTimeToTimeFields =
(RtlTimeToTimeFieldsT)GetProcAddress   
 (hLib,
"RtlTimeToTimeFields");

RtlTimeToTimeFields(&RtlTime, &tf);

FreeLibrary(hLib);

printf("%d %d %d %d %d %d\n",
tf.Year, tf.Month, tf.Day,
tf.Hour, tf.Minute, tf.Second);
return 0;
}
--8<---

with the following output on win2k.
9 0 10 0 9 10




Re: What is a leap second

2002-10-30 Thread György 'Nog' Jeney
> with the following output on win2k.
> 9 0 10 0 9 10

This is weird, I would have expected to get an output like: 2002 10 27 8 9 10
with the followingo patch applied...

nog.


Index: dlls/ntdll/time.c
===
RCS file: /home/wine/wine/dlls/ntdll/time.c,v
retrieving revision 1.20
diff -u -r1.20 time.c
--- dlls/ntdll/time.c   12 Sep 2002 22:07:03 -  1.20
+++ dlls/ntdll/time.c   30 Oct 2002 13:06:12 -
@@ -89,7 +89,11 @@
int LeapSecondCorrections, SecondsInDay, CurYear;
int LeapYear, CurMonth, GMTOffset;
long int Days;
-   LONGLONG Time = *(LONGLONG *)&liTime;
+   LONGLONG Time;
+
+   Time = liTime->s.HighPart;
+   Time <<= 32;
+   Time += liTime->s.LowPart;
 
/* Extract millisecond from time and convert time into seconds */
TimeFields->Milliseconds = (CSHORT) ((Time % TICKSPERSEC) / TICKSPERMSEC);
@@ -147,6 +151,7 @@
TimeFields->Month = (CSHORT) (CurMonth + 1);
TimeFields->Day = (CSHORT) (Days + 1);
 }
+
 /**
  *  RtlTimeFieldsToTime[NTDLL.@]
  *




Re: What is a leap second

2002-10-30 Thread György 'Nog' Jeney
>
>> György, could you check which other includes can be used if winternl.h
>> is absent? Else youll probably have to wait for somebody which has
>> it to compile your test.
>
> This is included in the latest platform SDK but it should also be
> defined in ntddk.h.

Ok, could somene rather compile this test and send its results? It will be
quite big...

nog.




timetest.c
Description: Binary data


Re: What is a leap second

2002-10-29 Thread György 'Nog' Jeney

> György, could you check which other includes can be used if winternl.h
> is absent? Else you''ll probably have to wait for somebody which has it
> to compile your test.

This is included in the latest platform SDK but it should also be defined
in ntddk.h.

nog.







Re: What is a leap second

2002-10-29 Thread Francois Gouget
On Wed, 30 Oct 2002, Malte Starostik wrote:

> On Tuesday 29 October 2002 20:52, György 'Nog' Jeney wrote:
> > > Advice: use it on Windows and check the result.
> >
> > Could someone compile this very simple test case under a system that has
> > RtlTimeToTimeFields (windows 98 doesnt export this from ntdll or
> > kernel32) and report the results?
> Sorry, but any chance this is using some Wine-specific headers?
>
> C:\>bcc32 timetest.c
> Borland C++ 5.6 for Win32 Copyright (c) 1993, 2002 Borland
> timetest.c:
> Error E2209 timetest.c 2: Unable to open include file 'winternl.h'

Not Wine specific, but winternl.h is a header that was created by
Microsoft only very recently in response to governent criticism. AFAIK
you will only find it in the latest Microsoft SDK... and in Wine.

-- 
Francois Gouget [EMAIL PROTECTED]http://fgouget.free.fr/
 Stolen from an Internet user:
  "f u cn rd ths, u cn gt a gd jb n cmptr prgrmmng !"





Re: What is a leap second

2002-10-29 Thread Vincent Béron
Le mar 29/10/2002 à 20:43, Malte Starostik a écrit :
> On Tuesday 29 October 2002 20:52, György 'Nog' Jeney wrote:
> > > Advice: use it on Windows and check the result.
> >
> > Could someone compile this very simple test case under a system that has
> > RtlTimeToTimeFields (windows 98 doesnt export this from ntdll or
> > kernel32) and report the results?
> Sorry, but any chance this is using some Wine-specific headers?
> 
> C:\>bcc32 timetest.c
> Borland C++ 5.6 for Win32 Copyright (c) 1993, 2002 Borland
> timetest.c:
> Error E2209 timetest.c 2: Unable to open include file 'winternl.h'

This header has been added to Wine because it is in the latest Windows
SDK (or DDK, can't recall exactly). The test should be compilable with
some other includes rather than this one if it is absent from your
installation.

György, could you check which other includes can be used if winternl.h
is absent? Else you'll probably have to wait for somebody which has it
to compile your test.

Vincent





Re: What is a leap second

2002-10-29 Thread Malte Starostik
On Tuesday 29 October 2002 20:52, György 'Nog' Jeney wrote:
> > Advice: use it on Windows and check the result.
>
> Could someone compile this very simple test case under a system that has
> RtlTimeToTimeFields (windows 98 doesnt export this from ntdll or
> kernel32) and report the results?
Sorry, but any chance this is using some Wine-specific headers?

C:\>bcc32 timetest.c
Borland C++ 5.6 for Win32 Copyright (c) 1993, 2002 Borland
timetest.c:
Error E2209 timetest.c 2: Unable to open include file 'winternl.h'
Error E2451 timetest.c 7: Undefined symbol 'TIME_FIELDS' in function WinMain
Error E2379 timetest.c 7: Statement missing ; in function WinMain
Error E2451 timetest.c 9: Undefined symbol 's' in function WinMain
Error E2451 timetest.c 10: Undefined symbol 's' in function WinMain
Error E2451 timetest.c 12: Undefined symbol 'tf' in function WinMain
Warning W8065 timetest.c 12: Call to function 'RtlTimeToTimeFields' with no 
prototype in function WinMain
Warning W8065 timetest.c 14: Call to function 'printf' with no prototype in 
function WinMain
Warning W8057 timetest.c 16: Parameter 'hInstance' is never used in function 
WinMain
Warning W8057 timetest.c 16: Parameter 'hPrev' is never used in function 
WinMain
Warning W8057 timetest.c 16: Parameter 'lpCmdLine' is never used in function 
WinMain
Warning W8057 timetest.c 16: Parameter 'cmd' is never used in function WinMain
*** 6 errors in Compile ***
C:\>

-Malte



msg13051/pgp0.pgp
Description: signature


Re: What is a leap second

2002-10-29 Thread Steve Langasek
On Wed, Oct 30, 2002 at 12:01:11AM +, David Laight wrote:
> On Tue, Oct 29, 2002 at 05:50:10PM -0600, Steve Langasek wrote:
> > On Tue, Oct 29, 2002 at 11:44:18PM +, David Laight wrote:

> > > What isn't clear (form the associated standards) is what you should do
> > > to the system clock at the point the leap second is added/subtracted.
> > > (Due to variations in the moment of intertia of the earth there
> > > have been seconds added aas well as  subtracted, even though the earth's
> > > rotation is slowing down because the moon keeps stealing angular
> > > momentum from it.)

> > Well, if your system clock keeps proper time as measured in seconds since
> > the epoch in UTC :), you don't need to do anything to the system clock;
> > the leap seconds should then be applied when displaying time in the local
> > time zone.

> No - leap seconds have to be ignored when counting time the epoch.
> Check the posix spec (www.opengroup.org for starters).

POSIX doesn't control the definition of "UTC".  If the system clock is
stored in UTC, then handling of leap seconds is a requirement when
converting from UTC to a local timezone.

Steve Langasek
postmodern programmer




Re: What is a leap second

2002-10-29 Thread David Laight
On Tue, Oct 29, 2002 at 05:50:10PM -0600, Steve Langasek wrote:
> On Tue, Oct 29, 2002 at 11:44:18PM +, David Laight wrote:
> 
> > What isn't clear (form the associated standards) is what you should do
> > to the system clock at the point the leap second is added/subtracted.
> > (Due to variations in the moment of intertia of the earth there
> > have been seconds added aas well as  subtracted, even though the earth's
> > rotation is slowing down because the moon keeps stealing angular
> > momentum from it.)
> 
> Well, if your system clock keeps proper time as measured in seconds since
> the epoch in UTC :), you don't need to do anything to the system clock;
> the leap seconds should then be applied when displaying time in the local
> time zone.

No - leap seconds have to be ignored when counting time the epoch.
Check the posix spec (www.opengroup.org for starters).

David

-- 
David Laight: [EMAIL PROTECTED]




Re: What is a leap second

2002-10-29 Thread Steve Langasek
On Tue, Oct 29, 2002 at 11:44:18PM +, David Laight wrote:

> What isn't clear (form the associated standards) is what you should do
> to the system clock at the point the leap second is added/subtracted.
> (Due to variations in the moment of intertia of the earth there
> have been seconds added aas well as  subtracted, even though the earth's
> rotation is slowing down because the moon keeps stealing angular
> momentum from it.)

Well, if your system clock keeps proper time as measured in seconds since
the epoch in UTC :), you don't need to do anything to the system clock;
the leap seconds should then be applied when displaying time in the local
time zone.

Steve Langasek
postmodern programmer




Re: What is a leap second

2002-10-29 Thread David Laight
On Tue, Oct 29, 2002 at 01:22:42PM -0600, Steve Langasek wrote:
> On Tue, Oct 29, 2002 at 06:45:42PM -, György 'Nog' Jeney wrote:
> 
> > While I was looking through dlls/ntdll/time.c I came across the following
> > two comments: "FIXME: Compute the number of leap second corrections here"
> > and "FIXME: get the GMT offset here" What do these this mean?
> 
> Just as there are leap years which have an extra day, from time to time
> it's necessary to adjust the clock by adding leap seconds because IIRC, a
> siderial day is not *exactly* 24 hours -- there's a little bit of drift 
> which adds up over time and needs to be corrected for.

I'm fairly sure that the POSIX standard for time ignores leap seconds.
So every calender day has 24 * 60 * 60 seconds (except when the
clock change for summertime).

What isn't clear (form the associated standards) is what you should do
to the system clock at the point the leap second is added/subtracted.
(Due to variations in the moment of intertia of the earth there
have been seconds added aas well as  subtracted, even though the earth's
rotation is slowing down because the moon keeps stealing angular
momentum from it.)

David

-- 
David Laight: [EMAIL PROTECTED]




RE: What is a leap second

2002-10-29 Thread Medland, Bill
> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:wine-devel-admin@;winehq.com]On
> Behalf Of György 'Nog' Jeney
> Sent: Tuesday, October 29, 2002 10:46 AM
> To: [EMAIL PROTECTED]
> Subject: What is a leap second
> 
> 
> 
> While I was looking through dlls/ntdll/time.c I came across 
> the following
> two comments: "FIXME: Compute the number of leap second 
> corrections here"
> and "FIXME: get the GMT offset here" What do these this mean?
> 
> nog.
> 
> 
> 
> 
(Trying to avoid repeating everyone else)

The best source I know for information on leap seconds is
http://tycho.usno.navy.mil/leapsec.html
That includes a link to the list of when the leap seconds have been.

I was also looking at "time" over the past couple of days, from the
"GetDateFormat" side of things (files/dos_fs.c).  I note that (Win98)
SystemTimeToFileTime etc do not include any leap seconds (i.e. file time
assumes no leap seconds).

Bill




Re: What is a leap second

2002-10-29 Thread Paul Millar

Hmmm, probably drifting OT here, but ...

> On Tue, Oct 29, 2002 at 06:45:42PM -, György 'Nog' Jeney wrote:
> > While I was looking through dlls/ntdll/time.c I came across the following
> > two comments: "FIXME: Compute the number of leap second corrections here"
> > and "FIXME: get the GMT offset here" What do these this mean?

I took this to be a coding question, rather than an astronomical one, so 
kept quite, but ...


On Tue, 29 Oct 2002, Steve Langasek wrote:
> Just as there are leap years which have an extra day, from time to time
> it's necessary to adjust the clock by adding leap seconds because IIRC, a
> siderial day is not *exactly* 24 hours -- there's a little bit of drift 
> which adds up over time and needs to be corrected for.

which is both right and wrong, so I thought I'd (hopefully ;) clear up any
confusion.  You're right, sidereal day != solar day.  But, that's not what
leap seconds are for.

A solar day is the time it takes from sun-transit (== "high noon") to
sun-transit and is exactly 24 solar-hours.  A solar-hour is what most
people think of as an hour.

A sidereal day is the time between Betelgeuse-transit and
Betelgeuse-transit (choosing a star at random ;)  It isn't 24 solar-hours,
but rather a smidgen over 23 hours, 56 minutes and 4 seconds (I calculated 
it as 4.1, but the web page I just check said 4.09 ...).

The two aren't the same because over the course of a year, the Earth
"gains" an extra day.  Nothing magical, just that even if the Earth didn't
spin (on its axis) you'd still have a day/night period as the Earth goes
around the sun.  Try it with a grapefruit and a satsuma to see what I
mean.  Keep the label saying "satsuma" pointing in the same direction and
rotate it around the grapefruit.  Over "one year", all around the satsuma
has faced the grapefruit, indicating a "day" has passed.

Ok, so what about leap seconds?  It turns out the Earth is slowing down.
Not by much, but atomic clocks are sufficiently accurate to measure this.  
GMT measure time by the Sun (e.g. solar dials), whereas UTC is time
measured by atomic clocks.  Mostly the difference is just names, but when
as Earth starts to slow down, a discrepancy develops and the atomic clocks
start to tell the "wrong" time.

So, to compensate for this, there are leap seconds. This just "jumps" UTC
back whenever the difference between GMT and UTC is around a second. 
They're introduced in a somewhat ad hoc fashion because the exact rate the 
Earth is slowing down isn't 100% predictable.

HTH

...


(Now returning you to your normal program :)


Paul Millar





Re: What is a leap second

2002-10-29 Thread György 'Nog' Jeney
> Advice: use it on Windows and check the result.

Could someone compile this very simple test case under a system that has
RtlTimeToTimeFields (windows 98 doesnt export this from ntdll or
kernel32) and report the results?

nog.




timetest.c
Description: Binary data


Re: What is a leap second

2002-10-29 Thread Steve Langasek
On Tue, Oct 29, 2002 at 06:45:42PM -, György 'Nog' Jeney wrote:

> While I was looking through dlls/ntdll/time.c I came across the following
> two comments: "FIXME: Compute the number of leap second corrections here"
> and "FIXME: get the GMT offset here" What do these this mean?

Just as there are leap years which have an extra day, from time to time
it's necessary to adjust the clock by adding leap seconds because IIRC, a
siderial day is not *exactly* 24 hours -- there's a little bit of drift 
which adds up over time and needs to be corrected for.

Steve Langasek
postmodern programmer




Re: What is a leap second

2002-10-29 Thread Vincent Béron
Le mar 29/10/2002 à 13:55, György 'Nog' Jeney a écrit :
> 
> While I was looking through dlls/ntdll/time.c I came across the following
> two comments: "FIXME: Compute the number of leap second corrections here"
> and "FIXME: get the GMT offset here" What do these mean?
> 
> nog.
> 

Leap seconds are seconds which are added every few years (I think
there's been ten-something since 1970) to account for the difference
between the time that atomic clocks count and the actual position of the
earth around the sun, or something like that. 

Since they are added "as needed", you can only be sure of those which
have already been added in the past. The first FIXME would be to account
for those (after checking MSDN, I can't say if RtlTimeToTimeFields() is
supposed to do it or not).

As for the second FIXME, MSDN is very shallow on details of what is
taken into account and what's not (see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/kmarch/hh/kmarch/k109_4gfm.asp).
 So I can't say either.

Advice: use it on Windows and check the result.

Vincent





What is a leap second

2002-10-29 Thread György 'Nog' Jeney

While I was looking through dlls/ntdll/time.c I came across the following
two comments: "FIXME: Compute the number of leap second corrections here"
and "FIXME: get the GMT offset here" What do these this mean?

nog.






What is a leap second

2002-10-29 Thread György 'Nog' Jeney

While I was looking through dlls/ntdll/time.c I came across the following
two comments: "FIXME: Compute the number of leap second corrections here"
and "FIXME: get the GMT offset here" What do these mean?

nog.