Fast RFC3339 compliant Python date-time library

Overview

udatetime: Fast RFC3339 compliant date-time library

Handling date-times is a painful act because of the sheer endless amount of formats used by people. Luckily there are a couple of specified standards out there like ISO 8601. But even ISO 8601 leaves to many options on how to define date and time. That's why I encourage using the RFC3339 specified date-time format.

udatetime offers on average 76% faster datetime object instantiation, serialization and deserialization of RFC3339 date-time strings. udatetime is using Python's datetime class under the hood and code already using datetime should be able to easily switch to udatetime. All datetime objects created by udatetime are timezone-aware. The timezones that udatetime uses are fixed-offset timezones, meaning that they don't observe daylight savings time (DST), and thus return a fixed offset from UTC all year round.

Support Performance optimized Implementation
Python 2 ✔️ ✔️ C
Python 3 ✔️ ✔️ C
PyPy ✔️ ✔️ Pure Python
>>> udatetime.from_string("2016-07-15T12:33:20.123000+02:00")
datetime.datetime(2016, 7, 15, 12, 33, 20, 123000, tzinfo=+02:00)

>>> dt = udatetime.from_string("2016-07-15T12:33:20.123000+02:00")
>>> udatetime.to_string(dt)
'2016-07-15T12:33:20.123000+02:00'

>>> udatetime.now()
datetime.datetime(2016, 7, 29, 10, 15, 24, 472467, tzinfo=+02:00)

>>> udatetime.utcnow()
datetime.datetime(2016, 7, 29, 8, 15, 36, 184762, tzinfo=+00:00)

>>> udatetime.now_to_string()
'2016-07-29T10:15:46.641233+02:00'

>>> udatetime.utcnow_to_string()
'2016-07-29T08:15:56.129798+00:00'

>>> udatetime.to_string(udatetime.utcnow() - timedelta(hours=6))
'2016-07-29T02:16:05.770358+00:00'

>>> udatetime.fromtimestamp(time.time())
datetime.datetime(2016, 7, 30, 17, 45, 1, 536586, tzinfo=+02:00)

>>> udatetime.utcfromtimestamp(time.time())
datetime.datetime(2016, 8, 1, 10, 14, 53, tzinfo=+00:00)

Installation

Currently only POSIX compliant systems are supported. Working on cross-platform support.

$ pip install udatetime

You might need to install the header files of your Python installation and some essential tools to execute the build like a C compiler.

Python 2

$ sudo apt-get install python-dev build-essential

or

$ sudo yum install python-devel gcc

Python 3

$ sudo apt-get install python3-dev build-essential

or

$ sudo yum install python3-devel gcc

Benchmark

The benchmarks compare the performance of equivalent code of datetime and udatetime. The benchmark measures the time needed for 1 million executions and takes the min of 3 repeats. You can run the benchmark yourself and see the results on your machine by executing the bench_udatetime.py script.

Benchmark interpreter summary

Python 2.7

$ python scripts/bench_udatetime.py
Executing benchmarks ...

============ benchmark_parse
datetime_strptime 10.6306970119
udatetime_parse 1.109801054
udatetime is 9.6 times faster

============ benchmark_format
datetime_strftime 2.08363199234
udatetime_format 0.654432058334
udatetime is 3.2 times faster

============ benchmark_utcnow
datetime_utcnow 0.485884904861
udatetime_utcnow 0.237742185593
udatetime is 2.0 times faster

============ benchmark_now
datetime_now 1.37059998512
udatetime_now 0.235424041748
udatetime is 5.8 times faster

============ benchmark_utcnow_to_string
datetime_utcnow_to_string 2.56599593163
udatetime_utcnow_to_string 0.685483932495
udatetime is 3.7 times faster

============ benchmark_now_to_string
datetime_now_to_string 3.68989396095
udatetime_now_to_string 0.687911987305
udatetime is 5.4 times faster

============ benchmark_fromtimestamp
datetime_fromtimestamp 1.38640713692
udatetime_fromtimestamp 0.287910938263
udatetime is 4.8 times faster

============ benchmark_utcfromtimestamp
datetime_utcfromtimestamp 0.533131837845
udatetime_utcfromtimestamp 0.279694080353
udatetime is 1.9 times faster

Python 3.5

$ python scripts/bench_udatetime.py
Executing benchmarks ...

============ benchmark_parse
datetime_strptime 9.90670353400003
udatetime_parse 1.1668808249999074
udatetime is 8.5 times faster

============ benchmark_format
datetime_strftime 3.0286041580000074
udatetime_format 0.7153575119999687
udatetime is 4.2 times faster

============ benchmark_utcnow
datetime_utcnow 0.5638177430000724
udatetime_utcnow 0.2548112540000602
udatetime is 2.2 times faster

============ benchmark_now
datetime_now 1.457822759999999
udatetime_now 0.26195338699994863
udatetime is 5.6 times faster

============ benchmark_utcnow_to_string
datetime_utcnow_to_string 3.5347913849999486
udatetime_utcnow_to_string 0.750341161999927
udatetime is 4.7 times faster

============ benchmark_now_to_string
datetime_now_to_string 4.854975383999999
udatetime_now_to_string 0.7411948169999505
udatetime is 6.6 times faster

============ benchmark_fromtimestamp
datetime_fromtimestamp 1.4233373309999706
udatetime_fromtimestamp 0.31758270299997093
udatetime is 4.5 times faster

============ benchmark_utcfromtimestamp
datetime_utcfromtimestamp 0.5633522409999614
udatetime_utcfromtimestamp 0.305099536000057
udatetime is 1.8 times faster

PyPy 5.3.1

$ python scripts/bench_udatetime.py
Executing benchmarks ...

============ benchmark_parse
datetime_strptime 2.31050491333
udatetime_parse 0.838973045349
udatetime is 2.8 times faster

============ benchmark_format
datetime_strftime 0.957178115845
udatetime_format 0.162060976028
udatetime is 5.9 times faster

============ benchmark_utcnow
datetime_utcnow 0.149839878082
udatetime_utcnow 0.149217844009
udatetime is as fast as datetime

============ benchmark_now
datetime_now 0.967023134232
udatetime_now 0.15003991127
udatetime is 6.4 times faster

============ benchmark_utcnow_to_string
datetime_utcnow_to_string 1.24988698959
udatetime_utcnow_to_string 0.632546901703
udatetime is 2.0 times faster

============ benchmark_now_to_string
datetime_now_to_string 2.13041496277
udatetime_now_to_string 0.607964038849
udatetime is 3.5 times faster

============ benchmark_fromtimestamp
datetime_fromtimestamp 0.903736114502
udatetime_fromtimestamp 0.0907990932465
udatetime is 10.0 times faster

============ benchmark_utcfromtimestamp
datetime_utcfromtimestamp 0.0890419483185
udatetime_utcfromtimestamp 0.0907027721405
udatetime is as fast as datetime

Why RFC3339

The RFC3339 specification has the following advantages:

  • Defined date, time, timezone, date-time format
  • 4 digit year
  • Fractional seconds
  • Human readable
  • No redundant information like weekday name
  • Simple specification, easily machine readable

RFC3339 format specification

date-fullyear   = 4DIGIT
date-month      = 2DIGIT  ; 01-12
date-mday       = 2DIGIT  ; 01-28, 01-29, 01-30, 01-31 based on
                          ; month/year
time-hour       = 2DIGIT  ; 00-23
time-minute     = 2DIGIT  ; 00-59
time-second     = 2DIGIT  ; 00-58, 00-59, 00-60 based on leap second
                          ; rules
time-secfrac    = "." 1*DIGIT
time-numoffset  = ("+" / "-") time-hour ":" time-minute
time-offset     = "Z" / time-numoffset

partial-time    = time-hour ":" time-minute ":" time-second [time-secfrac]

full-date       = date-fullyear "-" date-month "-" date-mday
full-time       = partial-time time-offset

date-time       = full-date "T" full-time

udatetime specific format addons:

  • time-secfrac from 1DIGIT up to 6DIGIT
  • time-secfrac will be normalized to microseconds
  • time-offset is optional. Missing time-offset will be treated as UTC.
  • spaces will be eliminated

Why in C?

The Python datetime library is flexible but painfully slow, when it comes to parsing and formating. High performance applications like web services or logging benefit from fast underlying libraries. Restricting the input format to one standard allows for optimization and results in speed improvements.

Comments
  • error: command 'gcc' failed with exit status 1

    error: command 'gcc' failed with exit status 1

    I tried to install this on CentOS 7 and got this error:

    ; pip install udatetime
    Collecting udatetime
      Using cached udatetime-0.0.2.tar.gz
    Building wheels for collected packages: udatetime
      Running setup.py bdist_wheel for udatetime ... error
      Complete output from command /home/usr/.virtualenvs/mead/bin/python -u -c "im
    port setuptools, tokenize;__file__='/tmp/pip-build-1v_otE/udatetime/setup.py';ex
    ec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'
    ), __file__, 'exec'))" bdist_wheel -d /tmp/tmpxo1peqpip-wheel- --python-tag cp27
    :
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-2.7
      creating build/lib.linux-x86_64-2.7/udatetime
      copying udatetime/__init__.py -> build/lib.linux-x86_64-2.7/udatetime
      running egg_info
      writing udatetime.egg-info/PKG-INFO
      writing top-level names to udatetime.egg-info/top_level.txt
      writing dependency_links to udatetime.egg-info/dependency_links.txt
      warning: manifest_maker: standard file '-c' not found
    
      reading manifest file 'udatetime.egg-info/SOURCES.txt'
      reading manifest template 'MANIFEST.in'
      writing manifest file 'udatetime.egg-info/SOURCES.txt'
      running build_ext
      building 'rfc3339' extension
      creating build/temp.linux-x86_64-2.7
      creating build/temp.linux-x86_64-2.7/src
      gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -
    fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-swit
    ches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall
     -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffe
    r-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -
    fPIC -I/usr/include/python2.7 -c ./src/rfc3339.c -o build/temp.linux-x86_64-2.7/
    ./src/rfc3339.o -Ofast
      In file included from /usr/include/python2.7/pyconfig.h:6:0,
                       from /usr/include/python2.7/Python.h:8,
                       from ./src/rfc3339.c:8:
      /usr/include/python2.7/pyconfig-64.h:1182:0: warning: "_POSIX_C_SOURCE" redefi
    ned [enabled by default]
       #define _POSIX_C_SOURCE 200112L
       ^
      In file included from /usr/include/math.h:27:0,
                       from ./src/rfc3339.c:1:
      /usr/include/features.h:168:0: note: this is the location of the previous defi
    nition
       # define _POSIX_C_SOURCE 200809L
       ^
      In file included from /usr/include/python2.7/pyconfig.h:6:0,
                       from /usr/include/python2.7/Python.h:8,
                       from ./src/rfc3339.c:8:
      /usr/include/python2.7/pyconfig-64.h:1204:0: warning: "_XOPEN_SOURCE" redefine
    d [enabled by default]
       #define _XOPEN_SOURCE 600
       ^
      In file included from /usr/include/math.h:27:0,
                       from ./src/rfc3339.c:1:
      /usr/include/features.h:170:0: note: this is the location of the previous defi
    nition
       # define _XOPEN_SOURCE 700
       ^
      ./src/rfc3339.c: In function ‘_parse_time’:
      ./src/rfc3339.c:250:9: error: ‘for’ loop initial declarations are only allowed
     in C99 mode
               for (unsigned int i = 0; i < 6; i++) {
               ^
      ./src/rfc3339.c:250:9: note: use option -std=c99 or -std=gnu99 to compile your
     code
      error: command 'gcc' failed with exit status 1
    
    
    opened by kierun 5
  • Cannot build on Python 3.9

    Cannot build on Python 3.9

    pip install udatetime fails to compile udatetime on Python 3.9. Works fine on 3.8.

    Tested on:

    • Python 3.9.0 on Ubuntu in Windows Subsystem for Linux on Windows 10
    • Python 3.9.0 on Darwin 19.6.0 (MacBook)

    Fails with similar errors on both.


    Stacktrace for Ubuntu in WSL
    $ env39_wsl/bin/pip install udatetime
    Collecting udatetime
      Downloading udatetime-0.0.16.tar.gz (13 kB)
    Using legacy 'setup.py install' for udatetime, since package 'wheel' is not installed.
    Installing collected packages: udatetime
        Running setup.py install for udatetime ... error
        ERROR: Command errored out with exit status 1:
         command: /mnt/c/Users/<redacted>/env39_wsl/bin/python3.9 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-1qm3faee/udatetime/setup.py'"'"'; __file__='"'"'/tmp/pip-install-1qm3faee/udatetime/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-lkuefh40/install-record.txt --single-version-externally-managed --compile --install-headers /mnt/c/Users/<redacted>/env39_wsl/include/site/python3.9/udatetime
             cwd: /tmp/pip-install-1qm3faee/udatetime/
        Complete output (36 lines):
        running install
        running build
        running build_py
        creating build
        creating build/lib.linux-x86_64-3.9
        creating build/lib.linux-x86_64-3.9/udatetime
        copying udatetime/__init__.py -> build/lib.linux-x86_64-3.9/udatetime
        copying udatetime/_pure.py -> build/lib.linux-x86_64-3.9/udatetime
        running egg_info
        writing udatetime.egg-info/PKG-INFO
        writing dependency_links to udatetime.egg-info/dependency_links.txt
        writing top-level names to udatetime.egg-info/top_level.txt
        reading manifest file 'udatetime.egg-info/SOURCES.txt'
        reading manifest template 'MANIFEST.in'
        writing manifest file 'udatetime.egg-info/SOURCES.txt'
        running build_ext
        building 'udatetime.rfc3339' extension
        creating build/temp.linux-x86_64-3.9
        creating build/temp.linux-x86_64-3.9/src
        x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security
     -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -D_PYTHON3=1 -I/mnt/c/Users/<redacted>/env39_wsl/include -I/usr/
    include/python3.9 -c ./src/rfc3339.c -o build/temp.linux-x86_64-3.9/./src/rfc3339.o -Ofast -std=c99
        ./src/rfc3339.c: In function ‘_gettime’:
        ./src/rfc3339.c:100:18: error: storage size of ‘t’ isn’t known
             struct timeb t;
                          ^
        ./src/rfc3339.c:101:5: warning: implicit declaration of function ‘ftime’; did you mean ‘stime’? [-Wimplicit-function-declaration]
             ftime(&t);
             ^~~~~
             stime
        ./src/rfc3339.c:100:18: warning: unused variable ‘t’ [-Wunused-variable]
             struct timeb t;
                          ^
        ./src/rfc3339.c: At top level:
        ./src/rfc3339.c:516:21: warning: ‘CAPI’ initialized and declared ‘extern’
         extern RFC3999_CAPI CAPI = {
                             ^~~~
        error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
        ----------------------------------------
    ERROR: Command errored out with exit status 1: /mnt/c/Users/<redacted>/env39_wsl/bin/python3.9 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-1qm3faee/udatetime/setup.py'"'"'; __file__='"'"'/tmp/pip-install-1qm3faee/udatetime/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-lkuefh40/install-record.txt --single-version-externally-managed --compile --install-headers /mnt/c/Users/<redacted>/env39_wsl/include/site/python3.9/udatetime Check the logs for full command output.
    
    Stacktrace for Darwin (MacBook) ``` Building wheels for collected packages: udatetime Building wheel for udatetime (setup.py): started Building wheel for udatetime (setup.py): finished with status 'error' ERROR: Command errored out with exit status 1: command: /Users/michael.overmeyer/src/github.com/closeio/ciso8601/benchmarking/.tox/py39/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/f5/5752mxwn72j_xmm44mc5xt900000gn/T/pip-install-sjrwiw8m/udatetime/setup.py'"'"'; __file__='"'"'/private/var/folders/f5/5752mxwn72j_xmm44mc5xt900000gn/T/pip-install-sjrwiw8m/udatetime/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/f5/5752mxwn72j_xmm44mc5xt900000gn/T/pip-wheel-ar7o0x3d cwd: /private/var/folders/f5/5752mxwn72j_xmm44mc5xt900000gn/T/pip-install-sjrwiw8m/udatetime/ Complete output (34 lines): running bdist_wheel running build running build_py creating build creating build/lib.macosx-10.9-x86_64-3.9 creating build/lib.macosx-10.9-x86_64-3.9/udatetime copying udatetime/__init__.py -> build/lib.macosx-10.9-x86_64-3.9/udatetime copying udatetime/_pure.py -> build/lib.macosx-10.9-x86_64-3.9/udatetime running egg_info writing udatetime.egg-info/PKG-INFO writing dependency_links to udatetime.egg-info/dependency_links.txt writing top-level names to udatetime.egg-info/top_level.txt reading manifest file 'udatetime.egg-info/SOURCES.txt' reading manifest template 'MANIFEST.in' writing manifest file 'udatetime.egg-info/SOURCES.txt' running build_ext building 'udatetime.rfc3339' extension creating build/temp.macosx-10.9-x86_64-3.9 creating build/temp.macosx-10.9-x86_64-3.9/src gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -D_PYTHON3=1 -I/Users/michael.overmeyer/src/github.com/closeio/ciso8601/benchmarking/.tox/py39/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c ./src/rfc3339.c -o build/temp.macosx-10.9-x86_64-3.9/./src/rfc3339.o -Ofast -std=c99 ./src/rfc3339.c:100:18: error: variable has incomplete type 'struct timeb' struct timeb t; ^ ./src/rfc3339.c:100:12: note: forward declaration of 'struct timeb' struct timeb t; ^ ./src/rfc3339.c:101:5: error: implicit declaration of function 'ftime' is invalid in C99 [-Werror,-Wimplicit-function-declaration] ftime(&t); ^ ./src/rfc3339.c:516:21: warning: 'extern' variable has an initializer [-Wextern-initializer] extern RFC3999_CAPI CAPI = { ^ 1 warning and 2 errors generated. error: command '/usr/bin/gcc' failed with exit code 1 ---------------------------------------- ERROR: Failed building wheel for udatetime Running setup.py clean for udatetime Failed to build udatetime Installing collected packages: aniso8601, six, python-dateutil, arrow, iso8601, monthdelta, enum34, iso8601utils, isodate, pytz, tzlocal, regex, dateparser, humanize, snaptime, pytzdata, pendulum, maya, times, moment, pyso8601, str2date, udatetime, pytimeparse, Babel, zulu, chardet, mbstrdecoder, typepy, msgfy, tcolorpy, DataProperty, pathvalidate, tabledata, pytablewriter, toml, filelock, appdirs, distlib, virtualenv, py, pluggy, pyparsing, packaging, tox Running setup.py install for udatetime: started Running setup.py install for udatetime: finished with status 'error' ERROR: Command errored out with exit status 1: command: /Users/michael.overmeyer/src/github.com/closeio/ciso8601/benchmarking/.tox/py39/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/f5/5752mxwn72j_xmm44mc5xt900000gn/T/pip-install-sjrwiw8m/udatetime/setup.py'"'"'; __file__='"'"'/private/var/folders/f5/5752mxwn72j_xmm44mc5xt900000gn/T/pip-install-sjrwiw8m/udatetime/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/f5/5752mxwn72j_xmm44mc5xt900000gn/T/pip-record-ooxk6ok5/install-record.txt --single-version-externally-managed --compile --install-headers /Users/michael.overmeyer/src/github.com/closeio/ciso8601/benchmarking/.tox/py39/include/site/python3.9/udatetime cwd: /private/var/folders/f5/5752mxwn72j_xmm44mc5xt900000gn/T/pip-install-sjrwiw8m/udatetime/ Complete output (34 lines): running install running build running build_py creating build creating build/lib.macosx-10.9-x86_64-3.9 creating build/lib.macosx-10.9-x86_64-3.9/udatetime copying udatetime/__init__.py -> build/lib.macosx-10.9-x86_64-3.9/udatetime copying udatetime/_pure.py -> build/lib.macosx-10.9-x86_64-3.9/udatetime running egg_info writing udatetime.egg-info/PKG-INFO writing dependency_links to udatetime.egg-info/dependency_links.txt writing top-level names to udatetime.egg-info/top_level.txt reading manifest file 'udatetime.egg-info/SOURCES.txt' reading manifest template 'MANIFEST.in' writing manifest file 'udatetime.egg-info/SOURCES.txt' running build_ext building 'udatetime.rfc3339' extension creating build/temp.macosx-10.9-x86_64-3.9 creating build/temp.macosx-10.9-x86_64-3.9/src gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -D_PYTHON3=1 -I/Users/michael.overmeyer/src/github.com/closeio/ciso8601/benchmarking/.tox/py39/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c ./src/rfc3339.c -o build/temp.macosx-10.9-x86_64-3.9/./src/rfc3339.o -Ofast -std=c99 ./src/rfc3339.c:100:18: error: variable has incomplete type 'struct timeb' struct timeb t; ^ ./src/rfc3339.c:100:12: note: forward declaration of 'struct timeb' struct timeb t; ^ ./src/rfc3339.c:101:5: error: implicit declaration of function 'ftime' is invalid in C99 [-Werror,-Wimplicit-function-declaration] ftime(&t); ^ ./src/rfc3339.c:516:21: warning: 'extern' variable has an initializer [-Wextern-initializer] extern RFC3999_CAPI CAPI = { ^ 1 warning and 2 errors generated. error: command '/usr/bin/gcc' failed with exit code 1 ---------------------------------------- ERROR: Command errored out with exit status 1: /Users/michael.overmeyer/src/github.com/closeio/ciso8601/benchmarking/.tox/py39/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/f5/5752mxwn72j_xmm44mc5xt900000gn/T/pip-install-sjrwiw8m/udatetime/setup.py'"'"'; __file__='"'"'/private/var/folders/f5/5752mxwn72j_xmm44mc5xt900000gn/T/pip-install-sjrwiw8m/udatetime/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/f5/5752mxwn72j_xmm44mc5xt900000gn/T/pip-record-ooxk6ok5/install-record.txt --single-version-externally-managed --compile --install-headers /Users/michael.overmeyer/src/github.com/closeio/ciso8601/benchmarking/.tox/py39/include/site/python3.9/udatetime Check the logs for full command output. ```
    opened by movermeyer 4
  • Consider moving rfc3339 module under udatetime

    Consider moving rfc3339 module under udatetime

    Hi!

    The udatetime package installs the rfc3339 module at the top-level, effectively shadowing the rfc3339 Python package. Do you think it is possible to move the rfc3339 module under udatetime?

    opened by iliastsi 3
  • Segmentation fault when i run utcnow frequently

    Segmentation fault when i run utcnow frequently

    I use ipython's timeit to benchmark udatetime like:

    %timeit -n 1000000 -r 10 udatetime.utcnow()

    when i repeat this command 5 times, it block serveral seconds and print : Segmentation fault (core dumped)

    datetime library is ok

    opened by xiewenlongs 3
  • Memory leak in from_string

    Memory leak in from_string

    udatetime version 0.13 leaks memory when calling from_string.

    Example (Python 2.7):

    import udatetime
    
    s = u"2008-09-08T22:47:31-07:00"
    while True:
        t = udatetime.from_string(s)
    

    The pure python version of from_string does not leak, only the C-extension (from_rfc3339_string) does.

    opened by ldanielburr 2
  • Memory leak

    Memory leak

    Please check using i.e. htop:

    #!/usr/bin/python3

    -- coding:utf8 --

    import udatetime while True: udatetime.now()

    It eats megabytes in seconds. I use your library, beacause it's very fast - but this problem was pretty hard to find.

    Sincerely Gregory

    bug 
    opened by gregers666 2
  • Support for variable length fraction seconds

    Support for variable length fraction seconds

    Currently only 3 and 6 digit fraction seconds are supported:

    time-secfrac can be either 3DIGIT for milliseconds or 6DIGIT for microseconds

    So 2 digit ones fail:

    In [1]: import udatetime
    
    In [2]: udatetime.from_string("2016-07-15T12:33:20.123000+02:00")
    Out[2]: datetime.datetime(2016, 7, 15, 12, 33, 20, 123000, tzinfo=+02:00)
    
    In [3]: udatetime.from_string("2016-07-15T12:33:20.123000Z")
    Out[3]: datetime.datetime(2016, 7, 15, 12, 33, 20, 123000, tzinfo=+00:00)
    
    In [4]: udatetime.from_string("2016-07-15T12:33:20.12Z")
    ---------------------------------------------------------------------------
    ValueError                                Traceback (most recent call last)
    <ipython-input-4-240aac401a4c> in <module>()
    ----> 1 udatetime.from_string("2016-07-15T12:33:20.12Z")
    
    ValueError: Invalid RFC3339 date-time string. Time invalid.
    

    I don't control data source so to use udatetime I would need to do string conversion which might eat all performance benefits. Would it be possible to support any fraction seconds up to 6 digits?

    opened by prymitive 2
  • Timestamp conversion does not handle daylight time

    Timestamp conversion does not handle daylight time

    It looks like udatetime does not handle changing utc offset for daylight savings time at different times of year, so the unit tests that use local timezone are failing when run in US Eastern Timezone.

    Here is the problem: https://github.com/freach/udatetime/blob/master/src/rfc3339.c#L74 udatetime uses the same UTC offset (in my case -4) for all dates, but datetime correctly uses -5 in January and -4 in August

    In[2]: import udatetime
    In[3]: from datetime import datetime
    
    In[4]: udatetime.fromtimestamp(1471046400)
    Out[4]: datetime.datetime(2016, 8, 12, 20, 0, tzinfo=--4:00)
    In[5]: datetime.fromtimestamp(1471046400)
    Out[5]: datetime.datetime(2016, 8, 12, 20, 0)
    
    In[6]: udatetime.fromtimestamp(1451606400)
    Out[6]: datetime.datetime(2015, 12, 31, 20, 0, tzinfo=--4:00)
    In[7]: datetime.fromtimestamp(1451606400)
    Out[7]: datetime.datetime(2015, 12, 31, 19, 0)
    
    In[8]: udatetime.fromtimestamp(0)
    Out[8]: datetime.datetime(1969, 12, 31, 20, 0, tzinfo=--4:00)
    In[9]: datetime.fromtimestamp(0)
    Out[9]: datetime.datetime(1969, 12, 31, 19, 0)
    
    

    Recommend changing the unit tests to avoid this problem buy using utcfromtimestamp() in the tests that do not supply a timestamp.

    In future, consider avoiding the problem entirely by always assuming that any datetime that does not come with an explicit timezone offset is UTC and never use the local timezone implicitly. Since this library is all about high performance for high volume throughput, it seems likely that most use cases will be using UTC anyway.

    bug 
    opened by pwoods25443 2
  • Explicitly include <sys/timeb.h> for ftime() and struct timeb

    Explicitly include for ftime() and struct timeb

    Needed to build on Python 3.9.

    Fixes: #32

    Can't see what changed in the Python 3.9 headers, where this used to be transitively included and isn't any more.

    Note, ftime() is deprecated, and should be replaced with gettimeofday(). This PR does not do that.

    opened by stefanor 1
  • Shared library is not properly linked with libm

    Shared library is not properly linked with libm

    udatetime uses the pow() math function in src/rfc3339.c, but doesn't link with libm.so.

    This was reported on Debian issue #954305, which also contains a possible fix.

    opened by iliastsi 1
  • Timestamp generation

    Timestamp generation

    It would be nice to have some faster timestamp generation that one get from pure datetime.timestamp() or time.time(). It can be very useful for any logging, etc. in case of fast application (like load testing using locust.io)

    opened by mkusz 1
  • datetimes cannot be pickled: attribute lookup FixedOffset_type on rfc3339 failed

    datetimes cannot be pickled: attribute lookup FixedOffset_type on rfc3339 failed

    When you try to pickle a datetime object, you get this error:

    >>> import udatetime
    >>> import pickle
    >>> d = udatetime.now()
    >>> pickle.dumps(d)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    _pickle.PicklingError: Can't pickle <class 'rfc3339.FixedOffset_type'>: attribute lookup FixedOffset_type on rfc3339 failed
    
    opened by federicoemartinez 0
  • rfc3339.FixedOffset_type is not copyable

    rfc3339.FixedOffset_type is not copyable

    Cannot use copy.deepcopy for datetime objects created with udatetime as deepcopy fails for rfc3339.FixedOffset_type. Example:

    >>> import udatetime
    >>> import datetime
    >>> import pytz
    >>> from copy import deepcopy
    >>> dtu = udatetime.now()
    >>> # deepcopy fails
    ... deepcopy(dtu)
    Traceback (most recent call last):
      File "<stdin>", line 2, in <module>
      File "/usr/local/lib/python3.7/copy.py", line 180, in deepcopy
        y = _reconstruct(x, memo, *rv)
      File "/usr/local/lib/python3.7/copy.py", line 274, in _reconstruct
        y = func(*args)
      File "/usr/local/lib/python3.7/copy.py", line 273, in <genexpr>
        args = (deepcopy(arg, memo) for arg in args)
      File "/usr/local/lib/python3.7/copy.py", line 180, in deepcopy
        y = _reconstruct(x, memo, *rv)
      File "/usr/local/lib/python3.7/copy.py", line 274, in _reconstruct
        y = func(*args)
    TypeError: function takes exactly 1 argument (0 given)
    >>> deepcopy(dtu.tzinfo)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/local/lib/python3.7/copy.py", line 180, in deepcopy
        y = _reconstruct(x, memo, *rv)
      File "/usr/local/lib/python3.7/copy.py", line 274, in _reconstruct
        y = func(*args)
    TypeError: function takes exactly 1 argument (0 given)
    >>> # compared to e.g. pytz as tzinfo
    ... tz = pytz.timezone('Europe/Helsinki')
    >>> dt = tz.localize(dtu.replace(tzinfo=None))
    >>> deepcopy(dt)
    datetime.datetime(2018, 7, 6, 19, 0, 32, 153444, tzinfo=<DstTzInfo 'Europe/Helsinki' EEST+3:00:00 DST>)
    

    Using e.g. pytz as tzinfo works fine. Using: Python 3.7.0 udatetime 0.0.16

    opened by Nipsuli 1
  • Support to rfc3339 Durations and Periods

    Support to rfc3339 Durations and Periods

    Durations:
    
       dur-second        = 1*DIGIT "S"
       dur-minute        = 1*DIGIT "M" [dur-second]
       dur-hour          = 1*DIGIT "H" [dur-minute]
       dur-time          = "T" (dur-hour / dur-minute / dur-second)
       dur-day           = 1*DIGIT "D"
       dur-week          = 1*DIGIT "W"
       dur-month         = 1*DIGIT "M" [dur-day]
       dur-year          = 1*DIGIT "Y" [dur-month]
       dur-date          = (dur-day / dur-month / dur-year) [dur-time]
    
       duration          = "P" (dur-date / dur-time / dur-week)
    
    
    
    Klyne, et. al.              Standards Track                    [Page 13]
    
    RFC 3339       Date and Time on the Internet: Timestamps       July 2002
    
    
    Periods:
    
       period-explicit   = iso-date-time "/" iso-date-time
       period-start      = iso-date-time "/" duration
       period-end        = duration "/" iso-date-time
    
       period            = period-explicit / period-start / period-end
    
    opened by gustavorps 0
  • Fix POSIX only support for _get_local_utc_offset()

    Fix POSIX only support for _get_local_utc_offset()

    The usage of the "tm_gmtoff" field in tm struct (src/rfc3339.c) is currently only supported by POSIX systems. For cross-platform compatibility fallbacks should be offered.

    opened by freach 1
Releases(0.0.17)
  • 0.0.17(Aug 12, 2022)

    Release tested on Python 2.7, Python 3.5 and Python 3.9.

    • Link shared library with libm #30
    • Explicitly include <sys/timeb.h> for ftime() and struct timeb
    • remove tz offset calculation on UTC timestamp
    Source code(tar.gz)
    Source code(zip)
  • 0.0.16(Feb 14, 2018)

  • 0.0.15(Feb 8, 2018)

  • 0.0.14(Dec 4, 2017)

    • Fix documentation to point out a minor issue with udatetime's timezones
    • Fix DST information, return proper DST information

    Thanks to @apyrgio

    Source code(tar.gz)
    Source code(zip)
  • 0.0.13(Aug 7, 2017)

Owner
Simon Pirschel
DevOps Specialist - Hire me for consultancy
Simon Pirschel
Predict bus arrival time using VertexAI and Nvidia's Jetson Nano

bus_prediction predict bus arrival time using VertexAI and Nvidia's Jetson Nano imagenet the command for imagenet.py look like this python3 /path/to/i

10 Dec 22, 2022
In real-world applications of machine learning, reliable and safe systems must consider measures of performance beyond standard test set accuracy

PixMix Introduction In real-world applications of machine learning, reliable and safe systems must consider measures of performance beyond standard te

Andy Zou 79 Dec 30, 2022
PyTorch implementation of Rethinking Positional Encoding in Language Pre-training

TUPE PyTorch implementation of Rethinking Positional Encoding in Language Pre-training. Quickstart Clone this repository. git clone https://github.com

Jake Tae 5 Jan 27, 2022
This GitHub repository contains code used for plots in NeurIPS 2021 paper 'Stochastic Multi-Armed Bandits with Control Variates.'

About Repository This repository contains code used for plots in NeurIPS 2021 paper 'Stochastic Multi-Armed Bandits with Control Variates.' About Code

Arun Verma 1 Nov 09, 2021
Next-Best-View Estimation based on Deep Reinforcement Learning for Active Object Classification

next_best_view_rl Setup Clone the repository: git clone --recurse-submodules ... In 'third_party/zed-ros-wrapper': git checkout devel Install mujoco `

Christian Korbach 1 Feb 15, 2022
FluidNet re-written with ATen tensor lib

fluidnet_cxx: Accelerating Fluid Simulation with Convolutional Neural Networks. A PyTorch/ATen Implementation. This repository is based on the paper,

JoliBrain 50 Jun 07, 2022
A collection of IPython notebooks covering various topics.

ipython-notebooks This repo contains various IPython notebooks I've created to experiment with libraries and work through exercises, and explore subje

John Wittenauer 2.6k Jan 01, 2023
The implementation of "Bootstrapping Semantic Segmentation with Regional Contrast".

ReCo - Regional Contrast This repository contains the source code of ReCo and baselines from the paper, Bootstrapping Semantic Segmentation with Regio

Shikun Liu 128 Dec 30, 2022
Efficient Sharpness-aware Minimization for Improved Training of Neural Networks

Efficient Sharpness-aware Minimization for Improved Training of Neural Networks Code for “Efficient Sharpness-aware Minimization for Improved Training

Angusdu 32 Oct 18, 2022
An off-line judger supporting distributed problem repositories

Thaw 中文 | English Thaw is an off-line judger supporting distributed problem repositories. Everyone can use Thaw release problems with license on GitHu

countercurrent_time 2 Jan 09, 2022
Code for Reciprocal Adversarial Learning for Brain Tumor Segmentation: A Solution to BraTS Challenge 2021 Segmentation Task

BRATS 2021 Solution For Segmentation Task This repo contains the supported pytorch code and configuration files to reproduce 3D medical image segmenta

Himashi Amanda Peiris 6 Sep 15, 2022
SymmetryNet: Learning to Predict Reflectional and Rotational Symmetries of 3D Shapes from Single-View RGB-D Images

SymmetryNet SymmetryNet: Learning to Predict Reflectional and Rotational Symmetries of 3D Shapes from Single-View RGB-D Images ACM Transactions on Gra

26 Dec 05, 2022
A MatConvNet-based implementation of the Fully-Convolutional Networks for image segmentation

MatConvNet implementation of the FCN models for semantic segmentation This package contains an implementation of the FCN models (training and evaluati

VLFeat.org 175 Feb 18, 2022
SpeechBrain is an open-source and all-in-one speech toolkit based on PyTorch.

The SpeechBrain Toolkit SpeechBrain is an open-source and all-in-one speech toolkit based on PyTorch. The goal is to create a single, flexible, and us

SpeechBrain 5.1k Jan 02, 2023
A Momentumized, Adaptive, Dual Averaged Gradient Method for Stochastic Optimization

MADGRAD Optimization Method A Momentumized, Adaptive, Dual Averaged Gradient Method for Stochastic Optimization pip install madgrad Try it out! A best

Meta Research 774 Dec 31, 2022
KITTI-360 Annotation Tool is a framework that developed based on python(cherrypy + jinja2 + sqlite3) as the server end and javascript + WebGL as the front end.

KITTI-360 Annotation Tool is a framework that developed based on python(cherrypy + jinja2 + sqlite3) as the server end and javascript + WebGL as the front end.

86 Dec 12, 2022
An efficient PyTorch implementation of the winning entry of the 2017 VQA Challenge.

Bottom-Up and Top-Down Attention for Visual Question Answering An efficient PyTorch implementation of the winning entry of the 2017 VQA Challenge. The

Hengyuan Hu 731 Jan 03, 2023
A rule-based log analyzer & filter

Flog 一个根据规则集来处理文本日志的工具。 前言 在日常开发过程中,由于缺乏必要的日志规范,导致很多人乱打一通,一个日志文件夹解压缩后往往有几十万行。 日志泛滥会导致信息密度骤减,给排查问题带来了不小的麻烦。 以前都是用grep之类的工具先挑选出有用的,再逐条进行排查,费时费力。在忍无可忍之后决

上山打老虎 9 Jun 23, 2022
Deep learning PyTorch library for time series forecasting, classification, and anomaly detection

Deep learning for time series forecasting Flow forecast is an open-source deep learning for time series forecasting framework. It provides all the lat

AIStream 1.2k Jan 04, 2023
Reimplementation of NeurIPS'19: "Meta-Weight-Net: Learning an Explicit Mapping For Sample Weighting" by Shu et al.

[Re] Meta-Weight-Net: Learning an Explicit Mapping For Sample Weighting Reimplementation of NeurIPS'19: "Meta-Weight-Net: Learning an Explicit Mapping

Robert Cedergren 1 Mar 13, 2020