Package: timeframe
TimeFrameTimeFrameIntroductionInstallExamplesInclusionNew APIDeprecatedDurationComparisonOverlapSummation (union)MinusAcknowledgmentContributionStargazers over timeIntroductionThis package makes the following calculations ondatetime:Adding two time frames, resulting in one bigger time frame or two disjoint one.Multiplying two time frames, resuling in either an overlapped time frame or
an empty one, depending on the two time frames.Substracting two time frames, resuling in one or several time frames.InstallInstalling the package is as simple as running the following command inside
your terminal:pipinstalltimeframeExamplesNOTE: You can always take a look at the test cases in thetestsdirectory to get a sense of how to use the package, but consider the below
examples first, because it's fairly easy to use.You need to importdatetimeas well asTimeFrame:fromdatetimeimportdatetimefromtimeframeimportTimeFrameInclusionNew API>>>tf1=TimeFrame(datetime(2021,1,1),datetime(2021,1,2))>>>tf2=TimeFrame(datetime(2021,1,1,12),datetime(2021,1,1,13))>>>tf2intf1TrueDeprecatedThis implies whether or not one time frame includes another; it can also be
used to check if adatetimeis inside oneTimeFrame.When you want to check if adatetimeis inside aTimeFrame:tf1=TimeFrame(datetime(2021,1,26,19),datetime(2021,1,26,20))tf1.includes(datetime(2021,1,26,19,30))# output: TrueWhen You want to check if an instance ofTimeFrameis inside another one:tf2=TimeFrame(datetime(2021,1,26,19,30),datetime(2021,1,26,19,40))tf1.includes(tf2)# output: Truetf3=TimeFrame(datetime(2021,1,26,19,45),datetime(2021,1,26,21,30))tf1.includes(tf3)# output: FalseDurationTimeFramehas a property nameddurationwhich can be used to retrieve the
total amount of seconds thatTimeFramehas:tf1.duration# output: 3600.0tf2.duration# output: 600.0tf3.duration# output: 6300.0ComparisonYou can always compare twoTimeFrameto see if one is greater than the other or not.
This comparison is based on theendof oneTimeFrameand thestartof the other.tf1>tf2# output: Falsetf3>tf2# output: TrueYou can also compare equality using either greater-equal sign, or a simple equal.tf1==tf2# output: Falsetf3>=tf2# output: TrueOverlapWhen you want to know how much two time frames have in common, use multiply sign:tf1*tf2# output: 2021-01-26T19:30:00#2021-01-26T19:40:00tf2*tf3# output: Empty TimeFrameYou can also check their duration as well:(tf1*tf2).duration# output: 600.0(tf2*tf3).duration# output: 0.0Summation (union)The summation sign is used to get the union of two time frames:tf1+tf2# output: 2021-01-26T19:00:00#2021-01-26T20:00:00(tf1+tf2).duration# output: 3600.0tf1+tf3# output: 2021-01-26T19:00:00#2021-01-26T21:30:00(tf1+tf3).duration# output: 9000.0MinusYou can also substract one time frame from the other, which will ultimately
result in either two disjoint time frames, or one unified time frame, depending
on the time frames.tf1-tf2# output:# 2021-01-26T19:00:00#2021-01-26T19:29:59.999999# 2021-01-26T19:40:00.000001#2021-01-26T20:00:00(tf1-tf2).duration# output: 2999.999998Substracting two disjoint time frames will return the first time frame as a result.tf2-tf3# output: 2021-01-26T19:30:00#2021-01-26T19:40:00(tf2-tf3).duration# output: 600.0(tf2-tf3)==tf2# output: TrueAcknowledgmentThank you for showing interest in this package. Feel free to contact me if you
feel like it. 🥂ContributionAny contribution of any size is greatly appreciated. Feel free to open a PR or
issue in the github page at any time. 🤗Stargazers over time