Puzzled with Time Server conversion problems?

Benjamin Schollnick junkster at nospam.rochester.rr.com
Sun Oct 3 22:44:43 EDT 1999


Folks,

	I'm running into some small problems with a RFC 868 timeserver
python daemon I've been working on.

	The main "killer" is simple, I can't find a way to have python 
generate
the correct "values" for the RFC.

	The RFC (868) is impressively vague:

		"When the connection is established, the server 
		 returns a 32-bit time value and closes the connection."

	Well, I've got the code working, and "standard" clients can connect
and work (somewhat), except they are receiving "bad" data, which goofs
up
the time calculation on their part.

	Here's the problem:

	I'm using Pythons time module, (specifically) time.time() to
generate the time information.  Even though time is specified to : 
"return the time
as a floating point number expressed in seconds since the epoch, in 
UTC", it doesn't
"match up" with the RFC results even when the 1900 vs 1970 date is 
taken into effect.

	The RFC states that "The time is the number of seconds since 00:00 @ 
1900 Jan 1.

	From my experimentation is GMTIME:

python GMTIME calcs							RFC 868
(Base 1970, Jan 1)						          (Base Jan 1, 1900)
Jan 1, 1970	-              18,000.0						2,208,988,800
Jan 1, 1976	-    189,320,400.0						2,398,291,200
Jan 1, 1980	- 3,155,550,800.0					2,524,421,600

I don't see how python's Jan 1, 1980 calcuation can exceed the RFC's 
calculation, unless the
calculation is returning *NON-LINEAR* results, which doesn't make 
sense if it's the # of secs since
Jan xxxx.

Also, I can't duplicate the RFC 868 values if I manually perform the 
calculations.

My "big question", is simple:

	Can anyone suggest a way to convert from pythons time.time() to the 
RFC date(s)?

	Included is my code for othe server, and the time programs I've been 
using for the
time/date experiments.

			- Benjamin

Timeserver.py

import time
import struct
#
#
# Python Times:                                         RFC 686
#
#       1, Jan 1970, 00:00 =        18,000.0    /       2,208,988,800 
 (2209006800)
#       1, Jan 1976, 00:00 =   189,320,400.0    /       2,398,291,200 
 (2208970800)
#       1, Jan 1980, 00:00 = 3,155,550,800.0    /       2,524,421,600 
 (-631129200)
#
#
epoch           = 18000 # Thu Jan 01 @ 00:00:00 @ 1970 (Win NT v4 & 
v1.5.2-0)

tserver_base    = 2,208,988,800.0

def timeserver_calculation():
        return time.time()

import sys

from socket import *

def server(host="", port=37, backlog=5):
        sock = socket (AF_INET, SOCK_STREAM)
        sock.bind (host, port)
        sock.listen (backlog)
        print "listening on port %s (%s, %s)" % (port, `host`, 
backlog)
        while 1:
                connection = (conn, addr) = sock.accept()
                print 'connected by %s \nat %s' % connection
                ft = timeserver_calculation()
                conn.send ( struct.pack("!i", ft))
                conn.close()

if __name__ == "__main__":
        server('', 37, 1)


>From GMTIME to floating (Manual Calculations)

import time
#
#       Constants
#
#secs_in_year    = 31536000      # 365*24*60*60
secs_in_year    = 365.1666666666667 * 24*60*60
print secs_in_year
secs_in_day     = 24*60*60      # 86400

timetuple       = time.gmtime(0)
total           = float(0)
print timetuple
total           = float(timetuple[0]-1900) * float(secs_in_year)
print total
total           = total + float(timetuple[7] * secs_in_day)
print total
total           = total + float(timetuple[5] + (timetuple[4] * 60) + 
(timetuple[3]*60*60))
print total
total = float(total)
print float(2208988800.0) - total

================================
Please feel free to copy any and or
all of this sig.
A little something for spam bots:

root at localhost postmaster at localhost admin at localhost
abuse at localhost postmaster at 127.0.0.1

Chairman William Kennard: bkennard at fcc.gov 
Commissioner Susan Ness: sness at fcc.gov
Commissioner Harold Furchtgott-Roth: hfurchtg at fcc.gov
Commissioner Michael Powell: mpowell at fcc.gov
Commissioner Gloria Tristani: gtristan at fcc.gov
consumerline at ftc.gov
fccinfo at fcc.gov
ssegal at fcc.gov





More information about the Python-list mailing list