Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/icholy/durationpy

Module for converting between datetime.timedelta and Go's time.Duration strings.
https://github.com/icholy/durationpy

Last synced: 1 day ago
JSON representation

Module for converting between datetime.timedelta and Go's time.Duration strings.

Awesome Lists containing this project

README

        

# durationpy

> Module for converting between `datetime.timedelta` and Go's Duration strings.

### Install

``` sh
$ pip install durationpy
```

### Parse

* `ns` - nanoseconds
* `us` - microseconds
* `ms` - millisecond
* `s` - second
* `m` - minute
* `h` - hour

``` py
# parse
td = durationpy.from_str("4h3m2s1ms")

# format
durationpy.to_str(td)
```

**Note:** nanosecond precision is lost because `datetime.timedelta` uses microsecond resolution.