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 Distribution

datetimetools-1.3.2.tar.gz (39.9 kB view details)

Uploaded Source

Built Distributions

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

datetimetools-1.3.2-cp314-cp314-win_arm64.whl (86.2 kB view details)

Uploaded CPython 3.14Windows ARM64

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

Uploaded CPython 3.14Windows x86-64

datetimetools-1.3.2-cp314-cp314-manylinux_2_38_x86_64.whl (68.9 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.38+ x86-64

datetimetools-1.3.2-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.2-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.2-cp313-cp313-win_arm64.whl (84.2 kB view details)

Uploaded CPython 3.13Windows ARM64

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

Uploaded CPython 3.13Windows x86-64

datetimetools-1.3.2-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.2-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.2-cp313-cp313-macosx_14_0_universal2.whl (61.3 kB view details)

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

datetimetools-1.3.2-cp312-cp312-win_arm64.whl (84.2 kB view details)

Uploaded CPython 3.12Windows ARM64

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

Uploaded CPython 3.12Windows x86-64

datetimetools-1.3.2-cp312-cp312-manylinux_2_38_x86_64.whl (68.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.38+ x86-64

datetimetools-1.3.2-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.2-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.2-cp311-cp311-win_arm64.whl (84.2 kB view details)

Uploaded CPython 3.11Windows ARM64

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

Uploaded CPython 3.11Windows x86-64

datetimetools-1.3.2-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.2-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.2-cp311-cp311-macosx_14_0_universal2.whl (61.3 kB view details)

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

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

Uploaded CPython 3.10Windows x86-64

datetimetools-1.3.2-cp310-cp310-manylinux_2_38_x86_64.whl (68.6 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.38+ x86-64

datetimetools-1.3.2-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.2-cp310-cp310-macosx_14_0_universal2.whl (61.3 kB view details)

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

File details

Details for the file datetimetools-1.3.2.tar.gz.

File metadata

  • Download URL: datetimetools-1.3.2.tar.gz
  • Upload date:
  • Size: 39.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for datetimetools-1.3.2.tar.gz
Algorithm Hash digest
SHA256 defc0d00fd32e7396db4874d08f870fc0f548096b809bdd5ef91f5de883af6c9
MD5 5f5f9a4ac0acbe007c02e867e63fe7ef
BLAKE2b-256 c80fe651df437eea9770dbf515e9d9304cc42840f1759176870e1adcb8bff3ed

See more details on using hashes here.

File details

Details for the file datetimetools-1.3.2-cp314-cp314-win_arm64.whl.

File metadata

File hashes

Hashes for datetimetools-1.3.2-cp314-cp314-win_arm64.whl
Algorithm Hash digest
SHA256 ef1729707e06660d1691d7484f2264cf7a70401b166ac3bc0ac3176396be6bf6
MD5 18109caddf172aba85f0bc61a596f842
BLAKE2b-256 facf35ce60d1bc582e8883a54d79dce9f59575e7127dbdc8957a74cfb9b641ad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for datetimetools-1.3.2-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 886d8b534ec1e468416d55c0a42ccdf1e65aec2df961847e9110ce12f1db214e
MD5 741355ccee18febccb2b87275eb8ef4f
BLAKE2b-256 511f0acffb47b91a952c967d6fe629ea7a32f1210afe0af628fe76fa547225e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for datetimetools-1.3.2-cp314-cp314-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 c443c12746ae6fce87103b34fd108057a86e18da0e04bbc125f2dfc83ddd56ea
MD5 ec0ae8d062510b9f8dce7c3fda5962ae
BLAKE2b-256 8d4bf03459b7b524700a15076747ddb19988c900180090ca4f57d364ff1f9b83

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for datetimetools-1.3.2-cp314-cp314-macosx_15_0_universal2.whl
Algorithm Hash digest
SHA256 2a33dda2034c5d3b8ac70773ff84982e3168c9e62ff23b83f5a6708974d471fb
MD5 f99981aacf71a5bafaaf671acfa5c90b
BLAKE2b-256 0b7c8adadc94575b15a667237b8e6294d737883c3b8f3970c5b3e50d7bf76674

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for datetimetools-1.3.2-cp314-cp314-macosx_14_0_universal2.whl
Algorithm Hash digest
SHA256 80d1f526a2a36a4590648622ca40e674ee5ccf474a49c8ea77be86a7f15e941b
MD5 c81de5278f2754b301f32a16938f9a3f
BLAKE2b-256 ad52f12b1cc1dfefeb60cfc5c081fad89d2fdb73b8363d1a7616ffa515a8e009

See more details on using hashes here.

File details

Details for the file datetimetools-1.3.2-cp313-cp313-win_arm64.whl.

File metadata

File hashes

Hashes for datetimetools-1.3.2-cp313-cp313-win_arm64.whl
Algorithm Hash digest
SHA256 80c562524bbbdd039b9dc47fe6e508a55cb7f7873168493dc82e74b3e05b28db
MD5 03ca60b218d80e821d593032bc0f67d7
BLAKE2b-256 6defce33139c05e2020582f629a149974b5167eb080364a4740dee6ba55a54df

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for datetimetools-1.3.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 6ae0cd1e75b7b8fbaddafcc590cc449225367ca7a40a5c353976d01ede288a82
MD5 15bbfb97d1978740c886abd0a97e4be7
BLAKE2b-256 e75caa42e2df3830a37a4921f88480c868984de99a6af9cec045b2c6c060c837

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for datetimetools-1.3.2-cp313-cp313-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 7fe3eace51dcd554b8acb927e36506842513c5f3a8bd55ddaca55b12b137a997
MD5 d891b7126afa073faad6bf3d7487dfbc
BLAKE2b-256 cbfbc42b3138267d21b887a391b5118af1b675815c58eaecfc729ac2c67bb66f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for datetimetools-1.3.2-cp313-cp313-macosx_15_0_universal2.whl
Algorithm Hash digest
SHA256 531eade3ceec69de78dfd08e4032b6966adff052d4bb5a6a9d5749e6a5989005
MD5 d748778a2b4b8e9337df4fb504ea0802
BLAKE2b-256 d9602df91a1c1e8bd726b1722ca116fcf166fefc177330e31229d9abcde67e8c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for datetimetools-1.3.2-cp313-cp313-macosx_14_0_universal2.whl
Algorithm Hash digest
SHA256 3896d14c364dca732ac409d74d813ff53d4969894e81febae97aa7a6dd6e3360
MD5 2f3a0d5b7f2c8bcac58860a5568b4e24
BLAKE2b-256 b6a7a82cac72a5ac5b92f9788d62b8bf94728a5ac04f0f0fe157243c42b26d3f

See more details on using hashes here.

File details

Details for the file datetimetools-1.3.2-cp312-cp312-win_arm64.whl.

File metadata

File hashes

Hashes for datetimetools-1.3.2-cp312-cp312-win_arm64.whl
Algorithm Hash digest
SHA256 e2a65ec25f167b09d4abcb338eaa8ff3d2b63cc3d01bbcc2f87d555c5ce82228
MD5 19b780ea7dca83a0b6767e72ab84d49a
BLAKE2b-256 54e07ac5caee3804c0707af9beea218e10654d32b7190d0896fd7c9d35537f67

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for datetimetools-1.3.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 1f50b7eb1fcfce6ff3585b69654d82d795d3e869149a049f1d9e9b8a22de2af5
MD5 29b55132bf38afced9934bf67354796d
BLAKE2b-256 a8ec144e9e76651eae16897c2617d1e00f334ef83e6f57dd3f949f2448fef999

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for datetimetools-1.3.2-cp312-cp312-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 9c84b88525412cef813769f676157a20f87516c7b6aac62ad36efd0ab6360042
MD5 3d30ab9fa6964615271f2680f8cc63ae
BLAKE2b-256 0c78af0fc8b6ff5f02d78f505fa14f5a7026445554e3caa72c97eff6d1171364

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for datetimetools-1.3.2-cp312-cp312-macosx_15_0_universal2.whl
Algorithm Hash digest
SHA256 64b18e8d14ed2cee16f2a6d46ffc1a849eada78fd7da22bce3d06dfc938b6f6e
MD5 943f1c2769ae3cd80d608c5322cd854b
BLAKE2b-256 f49c227a374026725a735fe1ee2a614ec35280fa9ea54fc01d0248152a5b6aca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for datetimetools-1.3.2-cp312-cp312-macosx_14_0_universal2.whl
Algorithm Hash digest
SHA256 d06beba73b2392069116667cfec65b0d3336331337fcc55e6a3bf4cfe0c2bea3
MD5 4e0d97607edecd023a91d7903bc4a883
BLAKE2b-256 3b4f0e1b51be88d56badf7680b7ac31265b79c0ad13f4fe894cccf9107173a72

See more details on using hashes here.

File details

Details for the file datetimetools-1.3.2-cp311-cp311-win_arm64.whl.

File metadata

File hashes

Hashes for datetimetools-1.3.2-cp311-cp311-win_arm64.whl
Algorithm Hash digest
SHA256 07996bef3edd478ce8a35ca59b5fd59a0d53b0f7eef73b4bac08e4ce38b9a5ea
MD5 efacf3ad23be43e35e136fca78baf9bd
BLAKE2b-256 758fcb78e0f68b059a2cfbb123ddaf57d18740bf37b8ba73097cf8c0be0ed378

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for datetimetools-1.3.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 bd50528f44942d70b278a5928fab133c66433b547c1e413ca3727a907b7c173f
MD5 95068cbc79761bf4fca39120b8e51a4a
BLAKE2b-256 c785ad76b01caa13062448477e0bee53f704e291bf7d64229e3cf0e6e6d199fb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for datetimetools-1.3.2-cp311-cp311-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 7571358b38224082a7237b4605349f6889a2825f5a3136b789c7d364002dfbfe
MD5 5681d4ebe6cb8a546afd9962a1aabf87
BLAKE2b-256 5c8bed5f20bdf917fcfcca4fcd3c338f021f275793436efc2e211816a737b482

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for datetimetools-1.3.2-cp311-cp311-macosx_15_0_universal2.whl
Algorithm Hash digest
SHA256 58599257056c63ee79e4e472b408989c65df57e80d49914cb4e0730085bfbbf2
MD5 0e781db83ff677cfb9c36f2647b41741
BLAKE2b-256 7e92b25e0113b849a6038ae7d0e6fac62acf1d0f15f34c9327fd69a2b34ac3df

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for datetimetools-1.3.2-cp311-cp311-macosx_14_0_universal2.whl
Algorithm Hash digest
SHA256 28cadfe299a920d09e6dd9a0924f00681ee764201ddd39ce7c7ea03af9655409
MD5 932eaa9277b6bb9d64628e54fc2730ed
BLAKE2b-256 7e8c79d9e0bc33780fe42f28ff887fa9a5648db212763366bc73de9d7c64a9b6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for datetimetools-1.3.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 64b2f72dd39356e1cd46e143a2f0f1f63d88bfbe370526e00d8c0e109bb77945
MD5 832e6397e0dab8c8556f042ccd75560a
BLAKE2b-256 d0d51f3237d180f41ad1ac5f28bffc0dbb86a319c04ef74dee966dcc4eb376d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for datetimetools-1.3.2-cp310-cp310-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 d47a2bf0d5a162dba42c2ce587fb2f50cccddecefccbbdcdbfa253a2072fb9f9
MD5 271b91dd4c5757390dc31da09236b248
BLAKE2b-256 1b0c963a7f4636bce954d736d1d3cd23c00299b500c8671255001120be3ac984

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for datetimetools-1.3.2-cp310-cp310-macosx_15_0_universal2.whl
Algorithm Hash digest
SHA256 d4b1c2a26bd494b48a15e2b832654a9b794773557746bf7a2f2b21d8b540c1de
MD5 2ab9506ea026ae8f6a246e163696e0e4
BLAKE2b-256 6063b076705a6a92c8b05a57e2b0f87057e1c5a0a978e7100d317699c3a546ce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for datetimetools-1.3.2-cp310-cp310-macosx_14_0_universal2.whl
Algorithm Hash digest
SHA256 f001f8f9aab5e296ab1adb57c9d2cc1fa401585dde982d73c65bae5c5d5db2d2
MD5 1598a79b092f4ad5c3f5e6ce9f9746fc
BLAKE2b-256 a58127918e294e670c34b34fa0e3adf512d2e65302ab0fa47ca5c548d4e24049

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