mirror of
https://github.com/openkmip/pykmip
synced 2025-12-29 22:53:26 +00:00
Merge pull request #79 from OpenKMIP/feat/update-date-time
Updating support for the DateTime primitive
This commit is contained in:
@@ -17,6 +17,7 @@ import logging
|
||||
import six
|
||||
import struct
|
||||
import sys
|
||||
import time
|
||||
|
||||
from struct import pack, unpack
|
||||
from enum import Enum
|
||||
@@ -833,11 +834,37 @@ class ByteString(Base):
|
||||
|
||||
|
||||
class DateTime(LongInteger):
|
||||
"""
|
||||
An encodeable object representing a date/time value.
|
||||
|
||||
A DateTime is one of the KMIP primitive object types. It is encoded as
|
||||
a signed, big-endian, 64-bit integer, representing a POSIX time value as
|
||||
the number of seconds since the Epoch (1970 January 1, 00:00:00 UTC). For
|
||||
more information, see Section 9.1 of the KMIP 1.1 specification.
|
||||
"""
|
||||
|
||||
def __init__(self, value=None, tag=Tags.DEFAULT):
|
||||
"""
|
||||
Create a DateTime.
|
||||
|
||||
Args:
|
||||
value (int): The value of the DateTime in number of seconds since
|
||||
the Epoch. See the time package for additional information.
|
||||
Optional, defaults to the current time.
|
||||
tag (Tags): An enumeration defining the tag of the LongInteger.
|
||||
Optional, defaults to Tags.DEFAULT.
|
||||
"""
|
||||
if value is None:
|
||||
value = int(time.time())
|
||||
super(DateTime, self).__init__(value, tag)
|
||||
self.type = Types.DATE_TIME
|
||||
|
||||
def __repr__(self):
|
||||
return "DateTime(value={0}, tag={1})".format(self.value, self.tag)
|
||||
|
||||
def __str__(self):
|
||||
return time.ctime(self.value)
|
||||
|
||||
|
||||
class Interval(Integer):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user