OpenQuizz
Une application de gestion des contenus pédagogiques
Timestamp Class Reference
Inheritance diagram for Timestamp:
Collaboration diagram for Timestamp:

Public Member Functions

def __init__ (self, seconds, nanoseconds=0)
 
def __repr__ (self)
 
def __eq__ (self, other)
 
def __ne__ (self, other)
 
def __hash__ (self)
 
def to_bytes (self)
 
def to_unix (self)
 
def to_unix_nano (self)
 
def to_datetime (self)
 

Static Public Member Functions

def from_bytes (b)
 
def from_unix (unix_sec)
 
def from_unix_nano (unix_ns)
 
def from_datetime (dt)
 

Data Fields

 seconds
 
 nanoseconds
 

Detailed Description

Timestamp represents the Timestamp extension type in msgpack.

When built with Cython, msgpack uses C methods to pack and unpack `Timestamp`. When using pure-Python
msgpack, :func:`to_bytes` and :func:`from_bytes` are used to pack and unpack `Timestamp`.

This class is immutable: Do not override seconds and nanoseconds.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  seconds,
  nanoseconds = 0 
)
Initialize a Timestamp object.

:param int seconds:
    Number of seconds since the UNIX epoch (00:00:00 UTC Jan 1 1970, minus leap seconds).
    May be negative.

:param int nanoseconds:
    Number of nanoseconds to add to `seconds` to get fractional time.
    Maximum is 999_999_999.  Default is 0.

Note: Negative times (before the UNIX epoch) are represented as negative seconds + positive ns.

Member Function Documentation

◆ __eq__()

def __eq__ (   self,
  other 
)
Check for equality with another Timestamp object

◆ __hash__()

def __hash__ (   self)

◆ __ne__()

def __ne__ (   self,
  other 
)
not-equals method (see :func:`__eq__()`)

◆ __repr__()

def __repr__ (   self)
String representation of Timestamp.

◆ from_bytes()

def from_bytes (   b)
static
Unpack bytes into a `Timestamp` object.

Used for pure-Python msgpack unpacking.

:param b: Payload from msgpack ext message with code -1
:type b: bytes

:returns: Timestamp object unpacked from msgpack ext payload
:rtype: Timestamp

◆ from_datetime()

def from_datetime (   dt)
static
Create a Timestamp from datetime with tzinfo.

Python 2 is not supported.

:rtype: Timestamp

◆ from_unix()

def from_unix (   unix_sec)
static
Create a Timestamp from posix timestamp in seconds.

:param unix_float: Posix timestamp in seconds.
:type unix_float: int or float.

◆ from_unix_nano()

def from_unix_nano (   unix_ns)
static
Create a Timestamp from posix timestamp in nanoseconds.

:param int unix_ns: Posix timestamp in nanoseconds.
:rtype: Timestamp

◆ to_bytes()

def to_bytes (   self)
Pack this Timestamp object into bytes.

Used for pure-Python msgpack packing.

:returns data: Payload for EXT message with code -1 (timestamp type)
:rtype: bytes

◆ to_datetime()

def to_datetime (   self)
Get the timestamp as a UTC datetime.

Python 2 is not supported.

:rtype: datetime.

◆ to_unix()

def to_unix (   self)
Get the timestamp as a floating-point value.

:returns: posix timestamp
:rtype: float

◆ to_unix_nano()

def to_unix_nano (   self)
Get the timestamp as a unixtime in nanoseconds.

:returns: posix timestamp in nanoseconds
:rtype: int

Field Documentation

◆ nanoseconds

nanoseconds

◆ seconds

seconds

The documentation for this class was generated from the following file: