Skip to main content

A package containing some simple tools to manage dates and times.

Project description

DateTimeTools

A package containing some simple tools to manage dates and times.

Installation

Installation requires cmake to be intalled in order to build libdatetime. It may be installed via apt:

sudo apt install cmake

or using pip:

pip3 install cmake

Install using pip3:

# Linux
pip3 install DateTimeTools

# MacOS
pip3 install DateTimeTools --no-build-isolation

NOTE: This module uses a C++ backend, which is compiled with CMake - please install CMake for your OS before installing this package.

Usage

Converting between different date/time formats

Usually this package deals with integer dates in the format yyyymmdd and floating point times in hours since the start of the day.

We can convert to a few different time formats:

import DateTimeTools as TT

Date = 20140102
ut = 15.0

#to unix time (seconds since 00:00 1970-01-01)
unixt = TT.UnixTime(Date,ut)
#and back
Date,ut = TT.UnixTimetoDate(unixt)

#to continuous time (hours since 00:00 1950-01-01)
utc = TT.ContUT(Date,ut)
#and back again
Date,ut = TT.contUTtoDate(utc)

#Julian day
jd = TT.JulDay(Date,ut)
#and back
Date,ut = TT.JulDaytoDate(jd)

#CDF Epoch (milliseconds since 00:00 0000-01-01)
cdfe = TT.CDFEpoch(Date,ut)
#and back
Date,ut = TT.CDFEpochtoDate(cdfe)

#get the python datetime
dt = TT.Datetime(Date,ut)
#or the reverse conversion
Date,ut = TT.DatetimetoDate(dt)

#convert hours since the start of the day to hours,minutes,seconds,milliseconds
hh,mm,ss,ms = TT.DectoHHMM(ut)
#and back
ut = TT.HHMMtoDec(hh,mm,ss,ms)

#Split dates into separate integers
yr,mn,dy = TT.DateSplit(Date)
#or the reverse
Date = TT.DateJoin(yr,mn,dy)

Formatted plot tick marks

The DTPlotLabel function can be used to change the plot labels on the x-axis of a matplotlib.pyplot plot such that they resemble human-readable times and dates.

For example:

import matplotlib.pyplot as plt

#some plot of a time series
#t is time either in unix time, ContUT, seconds from the start of the day
#or hours from the start of the day
plt.plot(t,x) 
ax = plt.gca()

#if we are plotting with t = TT.ContUT(Date,ut) 
#the function will be able to work out the date
#The TimeFMT keyword isn't needed here, by default = 'utc'
TT.DTPlotLabel(ax)

#similar to above - we can us unix time
#so t = TT.UnixTime(Date,ut)
#We must let the function know though
TT.DTPlotLabel(ax,TimeFMT='unix')

#With seconds from beginning of the day, we need to
#tell the function what Date starts at t == 0.0
#NOTE t can go beyond the range 0 < t < 24,
#the labels should include relevant dates
#Also, without the date keyword, just HH:MM(:SS) is shown
TT.DTPlotLabel(ax,TimeFMT='seconds',Date=20150101)

#Plotting with hours since the start of the day is similar
TT.DTPlotLabel(ax,TimeFMT='hours',Date=20190908)

Calculating time differences

#calculate the difference between two dates in days
ndays = TT.DateDifference(Date0,Date1)

#Similar to above, but include start and end times (still returns days)
ndays = TT.TimeDifference(Date0,ut0,Date1,ut1)

#We can find the middle time between two date/times
mDate,mut = TT.MidTime(Date0,ut0,Date1,ut1)

Filtering time series data

Given an evenly sampled time series, the lsfilter function can perform low-pass and high-pass filtering.

#t is the evenly smapled time axis
#x is the time series data

#we need to know the sampling interval in seconds
inter = t[1] - t[0]

#we can do a low-pass filter, we need to set 'high = inter'
#and 'low = lsec' which is the cutoff period in seconds
xlow = TT.lsfilter(x,inter,lowsec,inter)

#alternatively a high-pass filter can be used by setting
#'high = hsec' (the cutoff period in seconds) and 'low = inter'
xhigh = TT.lsfilter(x,hsec,inter,inter)

Miscellaneous functions

#calculate day number and year
year,dayno = TT.DayNo(Date)
#or return to original date format
Date = TT.DayNotoDate(year,dayno)

#Check if year(s) are leap year(s)
ly = TT.LeapYear(year)

#Add one day to a date
NextDate = TT.PlusDay(Date)
#or go back a day
PrevDate = TT.MinusDay(Date)

#Calculate the nearest index in a time/date array
#to a test time/date
ind = TT.NearestTimeIndex(DateArray,utArray,testDate,testut)

#check which indices of a time array are within two time limits
inds = TT.WithinTimeRange(t,t0,t1)
#or including dates
inds = TT.WithinTimeRange((d,t),(d0,t0),(d1,t1))
#alternatively, return a boolean array where each True element is within the range
b = TT.WithinTimeRange((d,t),(d0,t0),(d1,t1),BoolOut=True)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

datetimetools-1.3.1-cp314-cp314-win_amd64.whl (77.1 kB view details)

Uploaded CPython 3.14Windows x86-64

datetimetools-1.3.1-cp314-cp314-manylinux_2_38_x86_64.whl (68.8 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.38+ x86-64

datetimetools-1.3.1-cp314-cp314-macosx_15_0_universal2.whl (59.9 kB view details)

Uploaded CPython 3.14macOS 15.0+ universal2 (ARM64, x86-64)

datetimetools-1.3.1-cp314-cp314-macosx_14_0_universal2.whl (61.4 kB view details)

Uploaded CPython 3.14macOS 14.0+ universal2 (ARM64, x86-64)

datetimetools-1.3.1-cp313-cp313-win_amd64.whl (75.9 kB view details)

Uploaded CPython 3.13Windows x86-64

datetimetools-1.3.1-cp313-cp313-manylinux_2_38_x86_64.whl (68.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.38+ x86-64

datetimetools-1.3.1-cp313-cp313-macosx_15_0_universal2.whl (59.9 kB view details)

Uploaded CPython 3.13macOS 15.0+ universal2 (ARM64, x86-64)

datetimetools-1.3.1-cp313-cp313-macosx_14_0_universal2.whl (61.4 kB view details)

Uploaded CPython 3.13macOS 14.0+ universal2 (ARM64, x86-64)

datetimetools-1.3.1-cp312-cp312-win_amd64.whl (75.9 kB view details)

Uploaded CPython 3.12Windows x86-64

datetimetools-1.3.1-cp312-cp312-manylinux_2_38_x86_64.whl (68.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.38+ x86-64

datetimetools-1.3.1-cp312-cp312-macosx_15_0_universal2.whl (59.9 kB view details)

Uploaded CPython 3.12macOS 15.0+ universal2 (ARM64, x86-64)

datetimetools-1.3.1-cp312-cp312-macosx_14_0_universal2.whl (61.4 kB view details)

Uploaded CPython 3.12macOS 14.0+ universal2 (ARM64, x86-64)

datetimetools-1.3.1-cp311-cp311-win_amd64.whl (75.9 kB view details)

Uploaded CPython 3.11Windows x86-64

datetimetools-1.3.1-cp311-cp311-manylinux_2_38_x86_64.whl (68.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.38+ x86-64

datetimetools-1.3.1-cp311-cp311-macosx_15_0_universal2.whl (59.9 kB view details)

Uploaded CPython 3.11macOS 15.0+ universal2 (ARM64, x86-64)

datetimetools-1.3.1-cp311-cp311-macosx_14_0_universal2.whl (61.4 kB view details)

Uploaded CPython 3.11macOS 14.0+ universal2 (ARM64, x86-64)

datetimetools-1.3.1-cp310-cp310-win_amd64.whl (75.9 kB view details)

Uploaded CPython 3.10Windows x86-64

datetimetools-1.3.1-cp310-cp310-manylinux_2_38_x86_64.whl (68.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.38+ x86-64

datetimetools-1.3.1-cp310-cp310-macosx_15_0_universal2.whl (59.9 kB view details)

Uploaded CPython 3.10macOS 15.0+ universal2 (ARM64, x86-64)

datetimetools-1.3.1-cp310-cp310-macosx_14_0_universal2.whl (61.4 kB view details)

Uploaded CPython 3.10macOS 14.0+ universal2 (ARM64, x86-64)

File details

Details for the file datetimetools-1.3.1-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for datetimetools-1.3.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 5c9bea3a06ace40a247cd0c0287ae64e2325fd2e9a36d0fe9b14d33869107fda
MD5 5e83d8ec34843b7b167674b030c419de
BLAKE2b-256 ad6ed037e1fbb17268dd2408d5aaacdfdccc88b543de44c09858840b1d27a3e9

See more details on using hashes here.

File details

Details for the file datetimetools-1.3.1-cp314-cp314-manylinux_2_38_x86_64.whl.

File metadata

File hashes

Hashes for datetimetools-1.3.1-cp314-cp314-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 87f91ca526bc6aa92391028fd1f6d8e3b7eb294718fea0337453156f4c585292
MD5 b8b10b9f8d345cd6a9c122b57742fc4c
BLAKE2b-256 bad00a73b2fa2a9712059f2137fbfd770ad2f82e8c092e11f1b5e63d8a4d97e5

See more details on using hashes here.

File details

Details for the file datetimetools-1.3.1-cp314-cp314-macosx_15_0_universal2.whl.

File metadata

File hashes

Hashes for datetimetools-1.3.1-cp314-cp314-macosx_15_0_universal2.whl
Algorithm Hash digest
SHA256 21c14470d05b0188bd8f25bf578e84dda863fb7d187ef4df15b4f57569a797e0
MD5 607f2a8f6833e3892c3b700609aa7759
BLAKE2b-256 d5e3cc15e102f0c8725294cd7fa383e382f33b9154e2b614f729b729c4cf7661

See more details on using hashes here.

File details

Details for the file datetimetools-1.3.1-cp314-cp314-macosx_14_0_universal2.whl.

File metadata

File hashes

Hashes for datetimetools-1.3.1-cp314-cp314-macosx_14_0_universal2.whl
Algorithm Hash digest
SHA256 94baa79c54696be04c09d965e50a4312b68454b770d1fb6bb5f25986dd281549
MD5 69dba286a5a4da69a06a2f147c16f530
BLAKE2b-256 fa45229ece1ca0893aefd258db1f6d50b0b24d4f3868a07e50c484d123b6ed87

See more details on using hashes here.

File details

Details for the file datetimetools-1.3.1-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for datetimetools-1.3.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 b2fe3feb42058331c4f60aab7f46881abe5cd946190ca644c589fe5f58633a7f
MD5 c14c1a3ebb5a2307c7de32a2e1b59927
BLAKE2b-256 1fcf111c6e677fed5ff4ec75e50da2e02a739f73646632ab88a4e13940271040

See more details on using hashes here.

File details

Details for the file datetimetools-1.3.1-cp313-cp313-manylinux_2_38_x86_64.whl.

File metadata

File hashes

Hashes for datetimetools-1.3.1-cp313-cp313-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 c6333c67409d4ea85187141647360c7cff5144e314df313277c9e0dce7fa7194
MD5 ec93443a0d093c75c687ed8d1bf4d860
BLAKE2b-256 589bb92faaf453a077355af50e76870f49a16bb2315d1db36ea56db493f27a7e

See more details on using hashes here.

File details

Details for the file datetimetools-1.3.1-cp313-cp313-macosx_15_0_universal2.whl.

File metadata

File hashes

Hashes for datetimetools-1.3.1-cp313-cp313-macosx_15_0_universal2.whl
Algorithm Hash digest
SHA256 ff03e063b1b964af33fc2aead04a89c6ecff343e65b0d658b6788a45e977067f
MD5 ccf8bbc0c5b7857d1c0538f23e3fb11a
BLAKE2b-256 71c75e0e74e4fbcd4c1f7f212c89352b8dd526c8688ab834cda5777375e618de

See more details on using hashes here.

File details

Details for the file datetimetools-1.3.1-cp313-cp313-macosx_14_0_universal2.whl.

File metadata

File hashes

Hashes for datetimetools-1.3.1-cp313-cp313-macosx_14_0_universal2.whl
Algorithm Hash digest
SHA256 a6d0d2da40aec1b76e81d27095b77bd1804c0a35c1649119f7e860afdcd1f51a
MD5 e8128a945fb27f83d21f50d38c4d27c0
BLAKE2b-256 36f997cbc4c6a1b4912bf89a9e4dba72d484cca8f43e5d6f055158cee274d48b

See more details on using hashes here.

File details

Details for the file datetimetools-1.3.1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for datetimetools-1.3.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 0e9a609dba73b99997d3b39a76e99e91001427778a1697aef1dba754022c2c4d
MD5 560801a66a1823f006f9dedf1277ef33
BLAKE2b-256 beca945f155f35008b15b75e5538b75e085b4c4edd100df4427169eb4964a3da

See more details on using hashes here.

File details

Details for the file datetimetools-1.3.1-cp312-cp312-manylinux_2_38_x86_64.whl.

File metadata

File hashes

Hashes for datetimetools-1.3.1-cp312-cp312-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 157a4c967f6ce37fed0b4272662af7572de10690bc5adbc2325401bab027216e
MD5 05bd1cc452615c068eacc145ddc7cd72
BLAKE2b-256 c4c6b9ea88ee610ea0b09e10bdf75567b77a341c7eab39d2968b037124d52b29

See more details on using hashes here.

File details

Details for the file datetimetools-1.3.1-cp312-cp312-macosx_15_0_universal2.whl.

File metadata

File hashes

Hashes for datetimetools-1.3.1-cp312-cp312-macosx_15_0_universal2.whl
Algorithm Hash digest
SHA256 6157073d73a9f36b22b06c119f6168622696d629f66cc46409cdf6463101df9c
MD5 2d849ccd51951ff5245eb27c5923ccaa
BLAKE2b-256 8c31d38ce85777a262689a8f849d2aa9674f5ff1fd030b4afbde51c94df914a8

See more details on using hashes here.

File details

Details for the file datetimetools-1.3.1-cp312-cp312-macosx_14_0_universal2.whl.

File metadata

File hashes

Hashes for datetimetools-1.3.1-cp312-cp312-macosx_14_0_universal2.whl
Algorithm Hash digest
SHA256 f955a147e0af6129e0175f227c4d408b7cfbc98591fe0006b827ed8cf5f943ae
MD5 a701a3e9d49932ed530bf156ce50103d
BLAKE2b-256 36d0b55def73971799ebf3e75d0448f0f43e6236578daef05e88dca6d30b637a

See more details on using hashes here.

File details

Details for the file datetimetools-1.3.1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for datetimetools-1.3.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 6acf212dfee3def0980321420bb2bb97a04b19b8108142c2fbfbe1d1264c7d41
MD5 8ce9231eae0cd78d578cbc605a9a8dec
BLAKE2b-256 153b79c13fcc3bfed8e3a0d92e2b1a8b3560debeeaafb9ce735436cacd357fdb

See more details on using hashes here.

File details

Details for the file datetimetools-1.3.1-cp311-cp311-manylinux_2_38_x86_64.whl.

File metadata

File hashes

Hashes for datetimetools-1.3.1-cp311-cp311-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 b29ea96bce00616a20a93a6ecf4038c6d017fc554df50a5b90cb528d8f650812
MD5 6556a96162ac146359c6ebef40a654a1
BLAKE2b-256 cc36a1635eb1bb0f68fc51d77b0310d788c075a9f4fbd77e94b528389b8e3c4b

See more details on using hashes here.

File details

Details for the file datetimetools-1.3.1-cp311-cp311-macosx_15_0_universal2.whl.

File metadata

File hashes

Hashes for datetimetools-1.3.1-cp311-cp311-macosx_15_0_universal2.whl
Algorithm Hash digest
SHA256 1036ab9bc4435144cf1585ee62d855b4cc3348994220a314c623eb660725bd89
MD5 b6c7977dfa94d48b6f0e013c065af9b4
BLAKE2b-256 3f4ac79eaeb60942244ace996f00bf566524587a30400fc2f67e52a191897a91

See more details on using hashes here.

File details

Details for the file datetimetools-1.3.1-cp311-cp311-macosx_14_0_universal2.whl.

File metadata

File hashes

Hashes for datetimetools-1.3.1-cp311-cp311-macosx_14_0_universal2.whl
Algorithm Hash digest
SHA256 8faf71d1cc521199052a6eac8f0658fdb72f66260c1444b0ac7c9d8ce627c1c3
MD5 51751a089b5841b12ddd6162625455ab
BLAKE2b-256 0d8bf84613191da3956211a7c4396a515209088a40e3894d0f16c4e45b67ed85

See more details on using hashes here.

File details

Details for the file datetimetools-1.3.1-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for datetimetools-1.3.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 bb474e60f19dc1fc969e5f76541601ef2c5f80041b0df41bf374fbe6c12c9fcd
MD5 204d85500a3418902ad65ff4706f7aca
BLAKE2b-256 a3afb2ec05850dd4662e5748560f0197c4ac1116d4d404a85c9245e9695cae5d

See more details on using hashes here.

File details

Details for the file datetimetools-1.3.1-cp310-cp310-manylinux_2_38_x86_64.whl.

File metadata

File hashes

Hashes for datetimetools-1.3.1-cp310-cp310-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 57842a17c1bf64ee7d6b7024046fad3a0387363a267eef9022cc22ed94acfc9a
MD5 65731ccb2ce3e28ccf2237a71713c558
BLAKE2b-256 92497aae1f1d516c3842174e87ceecf0866a3993d5a63262082de33b143f441b

See more details on using hashes here.

File details

Details for the file datetimetools-1.3.1-cp310-cp310-macosx_15_0_universal2.whl.

File metadata

File hashes

Hashes for datetimetools-1.3.1-cp310-cp310-macosx_15_0_universal2.whl
Algorithm Hash digest
SHA256 d1cd713b6d6443b525969caf45e7f84c0439351bf5fd0e3a76feec3b803c966b
MD5 74461c728a251284e7d8acbaca12b027
BLAKE2b-256 88e36c50c0ac669cf0ae7fc16077af001e77f25cc8eb612c33f788c2c851cba6

See more details on using hashes here.

File details

Details for the file datetimetools-1.3.1-cp310-cp310-macosx_14_0_universal2.whl.

File metadata

File hashes

Hashes for datetimetools-1.3.1-cp310-cp310-macosx_14_0_universal2.whl
Algorithm Hash digest
SHA256 b974ebcd3051b9eccd97d400993a8c0506063b3f3d60ee9ed9e7d60beefd5235
MD5 d51b22c8b8fed89735d4d0dc4123601d
BLAKE2b-256 3a806353eb58d2c39429356ff0ed82dc535e700439fef80d1354358f78d76dbc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page