You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*`datemath()` object now returns the expected `datetime` object instead of an `Arrow` object
5
30
* added tests to catch invalid object types of helpers
6
31
7
-
## 1.5.4 (2021-04-20)
8
-
* skipped due to name conflict on pypi, all changes in this are from `1.5.3`
32
+
## [1.5.4] - 2021-04-20
33
+
### Unused
34
+
- skipped due to name conflict on pypi, all changes in this are from `1.5.3`
9
35
10
-
## 1.5.3 (2021-04-16)
11
-
*[FIX][Issue #25](https://github.com/nickmaccarthy/python-datemath/issues/25) - Fixed an issue where if you provided an invalid timestamp, i.e. `datemath('2')` you would not get an DateMathException back. Also bumped dependencies.
36
+
## [1.5.3] - 2021-04-16
37
+
### fixed
38
+
- FIX: [Issue #25](https://github.com/nickmaccarthy/python-datemath/issues/25) - Fixed an issue where if you provided an invalid timestamp, i.e. `datemath('2')` you would not get an DateMathException back. Also bumped dependencies.
12
39
13
-
## 1.5.2 (2020-10-01)
14
-
*[FIX][Issue #21](https://github.com/nickmaccarthy/python-datemath/issues/21) - Fixed an issue where if timezone offset was in a datetime string (ISO8601), the timezone of the returned datemath object would be UTC and not the timezone as specified in the datetime string.
40
+
## [1.5.2] - 2020-10-01
41
+
### fixed
42
+
- FIX: [Issue #21](https://github.com/nickmaccarthy/python-datemath/issues/21) - Fixed an issue where if timezone offset was in a datetime string (ISO8601), the timezone of the returned datemath object would be UTC and not the timezone as specified in the datetime string.
15
43
16
44
## 1.5.1 (2020-03-25)
17
45
18
-
*[FIX][Issue #15](https://github.com/nickmaccarthy/python-datemath/issues/15) - Fixed issue with parser finding invalid timeunits and throwing correct errors
19
-
*[NEW][Issue #16](https://github.com/nickmaccarthy/python-datemath/issues/16) - Added support for parser to accecpt a epoch/unix timestamp but throw an error on epoch milli's since arrow can't support that.
46
+
### fixed
47
+
- FIX: [Issue #15](https://github.com/nickmaccarthy/python-datemath/issues/15) - Fixed issue with parser finding invalid timeunits and throwing correct errors
48
+
### added
49
+
- Feat: [Issue #16](https://github.com/nickmaccarthy/python-datemath/issues/16) - Added support for parser to accecpt a epoch/unix timestamp but throw an error on epoch milli's since arrow can't support that.
20
50
21
-
## 1.5.0 (2019-11-09)
51
+
## 1.5.0 - 2019-11-09
22
52
23
-
*[FIX][Issue #12](https://github.com/nickmaccarthy/python-datemath/issues/12) - missing VERSION.txt. Added MANIFEST.in for sdist build
24
-
*[FIX][PR #13](https://github.com/nickmaccarthy/python-datemath/pull/13) - Fix `BaseException` to `Exception` inheritence, thank you for your contribution @yury-primer!
53
+
### fixed
54
+
-[Issue #12](https://github.com/nickmaccarthy/python-datemath/issues/12) - missing VERSION.txt. Added MANIFEST.in for sdist build
55
+
-[PR #13](https://github.com/nickmaccarthy/python-datemath/pull/13) - Fix `BaseException` to `Exception` inheritence, thank you for your contribution @yury-primer!
25
56
26
-
## 1.4.9 (2019-10-26)
57
+
## [1.4.9] - 2019-10-26
27
58
28
59
** PLEASE DO NOT USE THIS VERSION, use `1.5.0+` instead. This may not compile on your system due to a missing VERSION.txt which was fixed in `1.5.0+`**
29
-
*[FIX][Issue #9](https://github.com/nickmaccarthy/python-datemath/issues/9) && [Issue #8](https://github.com/nickmaccarthy/python-datemath/issues/8) - Fixing deprecated arrow `replace()` function with `shift()`.
30
-
*[FIX] Arrow upgrade to `0.15.2` to fix the above mentioned issues
31
-
*[NEW] Breakout of python2 and python3 requirements
32
-
*[NEW] Breakout of python2 and python3 specific CICD pipelines
33
-
*[NEW] Derecated the following python version (although they may still work, they are no longer supported) - `2.4`,`2.6`,`3.4`,`3.5`
34
-
*[FIX] Modifed `tests.py` to account for the timestamp change (tz is now `+0000`, instead of `-0000`)
35
-
*[FIX] replaced `ts = ts.replace(tzinfo=tz.gettz(timezone))` with `ts = ts.replace(tzinfo=timezone)` in `datemath.helpers.parseTime()` to fix [Issue #7](https://github.com/nickmaccarthy/python-datemath/issues/7)
36
-
37
-
## v1.4.8 (2019-10-25)
60
+
61
+
### fixed
62
+
-[FIX][Issue #9](https://github.com/nickmaccarthy/python-datemath/issues/9) && [Issue #8](https://github.com/nickmaccarthy/python-datemath/issues/8) - Fixing deprecated arrow `replace()` function with `shift()`.
63
+
-[FIX] Arrow upgrade to `0.15.2` to fix the above mentioned issues
64
+
-[FIX] Modifed `tests.py` to account for the timestamp change (tz is now `+0000`, instead of `-0000`)
65
+
-[FIX] replaced `ts = ts.replace(tzinfo=tz.gettz(timezone))` with `ts = ts.replace(tzinfo=timezone)` in `datemath.helpers.parseTime()` to fix [Issue #7](https://github.com/nickmaccarthy/python-datemath/issues/7)
66
+
### added
67
+
68
+
-[NEW] Breakout of python2 and python3 requirements
69
+
-[NEW] Breakout of python2 and python3 specific CICD pipelines
70
+
-[NEW] Derecated the following python version (although they may still work, they are no longer supported) - `2.4`,`2.6`,`3.4`,`3.5`
71
+
72
+
73
+
## [1.4.8] - 2019-10-25
74
+
** dont use this version **
38
75
* skipped due to name conflict on pypi, all changes are in `1.4.9`
39
76
40
-
## v1.4.7 (2017-11-10)
41
-
*[FIX] Fixed timezone for date strings: [Issue #6](https://github.com/nickmaccarthy/python-datemath/issues/6)
77
+
## [1.4.7] - 2017-11-10
78
+
### fixed
79
+
-[FIX] Fixed timezone for date strings: [Issue #6](https://github.com/nickmaccarthy/python-datemath/issues/6)
42
80
43
-
## v1.4.5 (2017-03-21)
44
-
*[NEW] Added roundDown functionality. Allows user to specify the default rounding for expressions such as `/d`.
45
-
* example - assuming the time is currently 2016-01-01 12:00:00, we should get the following
81
+
## [1.4.5] - 2017-03-21
82
+
### added
83
+
-[NEW] Added roundDown functionality. Allows user to specify the default rounding for expressions such as `/d`.
84
+
- example - assuming the time is currently 2016-01-01 12:00:00, we should get the following
46
85
```
47
86
>>> # now = 2016-01-01 14:00:00+00:00
48
87
>>> dm('now+/d', roundDown=False)
@@ -51,8 +90,10 @@
51
90
<Arrow [2016-01-01T00:00:00+00:00]>
52
91
```
53
92
54
-
## v1.4.4 (2016-12-28)
55
-
*[FIX] Fixed bug with expression logic and rounding: https://github.com/nickmaccarthy/python-datemath/pull/2
93
+
## [1.4.4] - 2016-12-28
94
+
### fixed
95
+
-[FIX] Fixed bug with expression logic and rounding: https://github.com/nickmaccarthy/python-datemath/pull/2
56
96
57
-
## 1.4.3 (2016-03-31)
58
-
*[NEW] Floats are now supported for days, hours, and seconds units. Example ```now-2.5d```, ```now-3.2h```. Any other unit other than days, hours, or seconds that is a float will be converted to an int and floored due to the datetime() module not being able to handle them.
97
+
## [1.4.3] - 2016-03-31
98
+
### added
99
+
[NEW] Floats are now supported for days, hours, and seconds units. Example ```now-2.5d```, ```now-3.2h```. Any other unit other than days, hours, or seconds that is a float will be converted to an int and floored due to the datetime() module not being able to handle them.
A date math (aka datemath) parser compatiable with the elasticsearch 'date math' format
8
-
9
-
## Why?
10
-
11
-
Working with date objects in python has always been interesting. Having a background in php, I have been looking for quite some time ( no pun intended ) for a way to do date time interpolation similar to php's ```strtotime()``` function. While the arrow module comes close, I needed something that could turn date math type strings into datetime objects for use in [tattle.io](http://tattle.io) and other projects I use in elasticsearch. I have found even more uses for it, including AWS cloudwatch and various other projects and hopefully you will too.
5
+
A date math (aka datemath) parser compatiable with the elasticsearch "date math" format
12
6
13
-
## What is date math?
7
+
## What is "date math"?
14
8
15
-
Date Math is the short hand arithmetic to find relative time to fixed moments in date and time. Similar to the SOLR date math format, Elasticsearch has its own built in format for short hand date math and this module aims to support that same coverage in python.
Date Math is the short hand arithmetic to find relative time to fixed moments in date and time. Similar to the SOLR date math format, we aim to support that same coverage in python.
19
10
20
11
> The date type supports using date math expression when using it in a query/filter (mainly makes sense in range query/filter).
21
12
>
@@ -31,6 +22,7 @@ Documentation from elasticsearch:
31
22
32
23
## Unit Maps
33
24
25
+
The "unit maps" here define the shorthand sytax for the dates/timeframes we are working with:
34
26
```yaml
35
27
y or Y = 'year'
36
28
M = 'month'
@@ -39,17 +31,14 @@ d or D = 'day'
39
31
w = 'week'
40
32
h or H = 'hour'
41
33
s or S = 'second'
42
-
```
43
-
44
-
## Install
45
-
46
-
```python
47
-
pip install python-datemath
34
+
now = <current_time_and_date>
48
35
```
49
36
50
37
## Examples
51
38
52
-
Assuming our datetime is currently: `2016-01-01T00:00:00-00:00`
39
+
Here are some examples of using date math to find dates both in the past and in the future
40
+
41
+
Assuming our "now" datetime is currently: `2016-01-01T00:00:00-00:00`
53
42
54
43
```yaml
55
44
Expression: Result:
@@ -73,7 +62,7 @@ now/Y 2016-12-31T23:59:59+00:00
73
62
74
63
## Usage
75
64
76
-
By default datemath return an arrow date object representing your timestamp.
65
+
If you use the `dm` function in the datemath module, we will return an arrow date object representing your timestamp.
77
66
78
67
```python
79
68
>>>from datemath import dm
@@ -118,8 +107,25 @@ If you would rather have a string, you can use arrow's ```.format()``` method.
118
107
u'2015.12.18'
119
108
```
120
109
121
-
Rather have a python datetime object instead? Just pass along the 'datetime' type
110
+
If you would rather have your time object come back in standard python `datetime`, use the `datemath` function instead:
If you want a Epoch timestamp back instead, we can do that.
138
+
If you want a Epoch timestamp back instead, we can do that too.
147
139
148
140
```python
149
141
>>> dm('now+2d-1m', type='timestamp')
@@ -152,7 +144,7 @@ If you want a Epoch timestamp back instead, we can do that.
152
144
153
145
## What timezone are my objects in?
154
146
155
-
By default all object returned by datemath are in UTC.
147
+
By default all objects returned by datemath are in UTC.
156
148
157
149
If you want them them back in a different timezone, just pass along the ```tz``` argument. Timezone list can be found here: [https://gist.github.com/pamelafox/986163](https://gist.github.com/pamelafox/986163)
158
150
@@ -188,6 +180,12 @@ Note - currently timestrings with a timezone offset and the usage of the ```tz``
188
180
<Arrow [2016-01-01T00:00:00-05:00]>
189
181
```
190
182
183
+
## Install
184
+
185
+
```python
186
+
pip install python-datemath
187
+
```
188
+
191
189
## Debugging
192
190
193
191
If you would like more verbose output to debug the process of what datemath is doing, simply set `export DATEMATH_DEBUG=true` in your shell then run some datemath tests. To stop debugging, run `unset DATEMATH_DEBUG`.
0 commit comments