MCPcopy Create free account
hub / github.com/ActiveState/code / DateFromJDNumber

Function DateFromJDNumber

recipes/Python/117215_A_Date_module/recipe-117215.py:280–296  ·  view source on GitHub ↗

Returns a date corresponding to the given Julian day number.

(n)

Source from the content-addressed store, hash-verified

278
279#More conversion functions.
280def DateFromJDNumber(n):
281 """Returns a date corresponding to the given Julian day number."""
282 if not isinstance(n, int):
283 raise TypeError, "%s is not an integer." % str(n)
284
285 a = n + 32044
286 b = (4*a + 3)//146097
287 c = a - (146097*b)//4
288 d = (4*c + 3)//1461
289 e = c - (1461*d)//4
290 m = (5*e + 2)//153
291
292 ret = Date()
293 ret.day = e + 1 - (153*m + 2)//5
294 ret.month = m + 3 - 12*(m//10)
295 ret.year = 100*b + d - 4800 + m/10
296 return ret
297
298def DateFromCOM(t):
299 """Converts a COM time directly into the Date format."""

Callers 1

__add__Method · 0.85

Calls 2

strFunction · 0.85
DateClass · 0.70

Tested by

no test coverage detected