* Added method idatetime.join_values() .

master
Wirawan Purwanto 9 years ago
parent 86e4e8fd51
commit 1c5ec91b64
  1. 8
      TESTS/test_datetime.py
  2. 21
      datetime0_idt.py

@ -6,7 +6,7 @@ from time import localtime, gmtime, strftime
from wpylib.datetime0_idt import idatetime from wpylib.datetime0_idt import idatetime
from wpylib.datetime import utime_to_iso from wpylib.datetime import utime_to_iso
from pprint import pprint
def test_idt_01(): def test_idt_01():
@ -17,6 +17,12 @@ def test_idt_01():
idt = idatetime(iidt) idt = idatetime(iidt)
print "integer value = %+18d" % idt.idt print "integer value = %+18d" % idt.idt
print "iso8601 format = %s" % idt.str_iso8601() print "iso8601 format = %s" % idt.str_iso8601()
R = idt.split_values()
print("split values:")
pprint(R.__dict__)
iidt_rejoined = idt.join_values(R)
print("iidt rejoined = %+18d" % iidt_rejoined)
def test_u2i_01(): def test_u2i_01():

@ -32,6 +32,7 @@ where:
The time is always expressed in terms of UTC to eliminate ambiguity of The time is always expressed in terms of UTC to eliminate ambiguity of
time zone, daylight savings time, etc. time zone, daylight savings time, etc.
CAVEAT: The resolution of the time is only on the order of millisecond. CAVEAT: The resolution of the time is only on the order of millisecond.
Linux OS, for example, allows resolution down to nanoseconds!
This is a 17-decimal-digit integer, which fits in a 64-bit range (9.22e+18). This is a 17-decimal-digit integer, which fits in a 64-bit range (9.22e+18).
@ -71,6 +72,26 @@ class idatetime(object):
R.microsecond = R.millisecond * 1000 R.microsecond = R.millisecond * 1000
return R return R
def join_values(self, R=None):
"""Joins the values contained in data structure 'R' to create a
composite integer date.
This is the converse of function 'split_values'.
"""
if R is None:
R = self.R
if hasattr(R, 'microsecond'):
millisecond = R.microsecond // 1000
elif hasattr(R, 'millisecond'):
millisecond = R.millisecond
return R.year * 10000000000000 \
+ R.month * 100000000000 \
+ R.day * 1000000000 \
+ R.hour * 10000000 \
+ R.minute * 100000 \
+ R.second * 1000 \
+ millisecond
def to_datetime(self): def to_datetime(self):
"""Converts the object value to standard python datetime object. """Converts the object value to standard python datetime object.
""" """

Loading…
Cancel
Save