Skip to content

0.3.6

Compare
Choose a tag to compare
@kalaspuff kalaspuff released this 06 Dec 14:15
· 147 commits to master since this release
0.3.6
4700f07
  • Added support to transform from (and if necessary, to) Protocol Buffers messages of type google.protobuf.Timestamp as well as from binary data representing a google.protobuf.Timestamp protobuf message. (see additional info below).
  • Support for timezones delta used with a whitespace before specification (for example "2022-12-06T13:37:34.037042 +01:00" works the same as "2022-12-06T13:37:34.037042+01:00")

Possible to transform a value encoded as a google.protobuf.Timestamp protobuf message in the same way you would from any other value.

# Using a google.protobuf.Timestamp message as input to utcnow
import utcnow
from google.protobuf.timestamp_pb2 import Timestamp
msg = Timestamp(seconds=1670329924, nanos=170660000)
result = utcnow.get(msg)
# "2022-12-06T12:32:04.170660Z"
# Using the binary data from a google.protobuf.Timestamp message
import utcnow
protobuf_msg_binary = b"\x08\xc4\xec\xbc\x9c\x06\x10\xa0\xa1\xb0Q"
result = utcnow.get(protobuf_msg_binary)
# "2022-12-06T12:32:04.170660Z"

You can also generate a new google.protobuf.Timestamp message using utcnow.as_protobuf()

import utcnow
msg = utcnow.as_protobuf("1984-08-01 22:30:47.234003Z")
# <class 'google.protobuf.timestamp_pb2.Timestamp'>
# · seconds: 460247447
# · nanos: 234003000

Note that the protobuf package has to be installed to make use of the above functionality. For convenience, it's also possible to install utcnow with protobuf support using the protobuf extras.

$ pip install utcnow[protobuf]