Skip to content

Releases: kalaspuff/utcnow

0.3.8

04 Oct 12:20
0.3.8
01650f7
Compare
Choose a tag to compare
  • Included inline documentation for the functions and parts developers may touch in this library.
  • Added modifier and timediff support for milliseconds, microseconds and nanoseconds (although nanosecond precision will currently not use native nanoseconds, and will return microseconds * 1000). See details in #133.
  • Refactoring of the library to actually use a ModuleType instead of creating a class object (that was used as as a drop in for the module) when importing utcnow.
  • Addition of a context manager available at utcnow.synchronizer to freeze the current time of utcnow to a specific value of your choice or to the current time when entering the context manager. See details in #133 and the repo documentation.

0.3.7

15 Aug 18:19
0.3.7
36ed88e
Compare
Choose a tag to compare
  • Support for Python 3.12.

0.3.6

06 Dec 14:15
0.3.6
4700f07
Compare
Choose a tag to compare
  • 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]

0.3.5

25 Oct 15:10
0.3.5
b106f3e
Compare
Choose a tag to compare
  • Python 3.11 added to test matrix and trove classifiers to officially claim support.

0.3.4

17 Oct 15:31
a7ec61a
Compare
Choose a tag to compare
  • Added optional modifier argument to the timestamp functions.

    import utcnow
    
    utcnow.rfc3339_timestamp("2000-01-01", "+30s")
    # 2000-01-01T00:00:30.000000Z
    
    utcnow.rfc3339_timestamp("2000-01-01", "-1d")
    # 1999-12-31T00:00:00.000000Z
    
    utcnow.rfc3339_timestamp("2022-10-17 15:30:00", "+5.5h")
    # 2022-10-17T21:00:00.000000Z
    
    utcnow.rfc3339_timestamp("now", "+365d")
    # 2023-10-17T15:26:55.706575Z

0.3.3

17 Oct 14:26
3b7d284
Compare
Choose a tag to compare
  • utcnow can now be used as cli by installing utcnow-cli or using the cli extras of utcnow.

    # install utcnow with extras: cli
    pip install utcnow[cli]
    # equivalent to installing utcnow-cli
    pip install utcnow-cli
    code ~$ utcnow
    2022-10-17T14:25:04.481821Z
    
    usage:
      utcnow [values ...]              | default     output in rfc3339 format
      utcnow --unixtime [values ...]   | short: -u   output as unixtime
      utcnow --diff <from> <to>        | short: -d   diff in seconds: from -> to
    
    help:
      utcnow --help                    | short: -h   display this message
      utcnow --version                 | short: -v   installed version (0.3.3)
    

0.3.2

06 Apr 08:03
d1f6a80
Compare
Choose a tag to compare
  • Added Added utcnow.get_today() / utcnow.as_date_string(value) which returns the date part in string format. Note that the date string that is returned does not include timezone information. The function take an optional value argument which will transform input to a UTC timezoned timestamp from which it'll extract the date.
  • An optional tz keyword argument to utcnow.get_today(tz=UTC) can be used to get the current date for another timezone than UTC (which otherwise is the default behaviour). The value for tz should be a datetime.tzinfo value (such as produced from timezone libraries, for example pytz.timezone(tz_str) or tzlocal.get_localzone()) or a string describing an utcoffset, such as "+02:00" or "-06:00".

0.3.1

14 Mar 16:07
8d11dd8
Compare
Choose a tag to compare
  • Added Python 3.10 as trove classifier.
  • Added test matrix to include Python 3.10.

0.3.0

29 Jun 23:58
d662509
Compare
Choose a tag to compare
  • Conversion to unixtime.
  • Timediff functionality to get the delta of the specified unit between two utcnow timestamps.
  • utcnow.now() is now also available to get the current timestamp.
  • Added documentation.

0.2.2

26 Feb 07:05
14712a9
Compare
Choose a tag to compare
  • Higher throughput, faster timestamp resolution.
  • Added support for unixtime input values.
utcnow.get(0)
# "1970-01-01T00:00:00.000000Z"

utcnow.get(time.time())
# "2021-02-26T07:04:27.973312Z"