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
Copy file name to clipboardExpand all lines: CHANGELOG.md
+3Lines changed: 3 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,8 @@
1
1
# Changelog
2
2
3
+
## 1.5.2 (2020-10-01)
4
+
*[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.
5
+
3
6
## 1.5.1 (2020-03-25)
4
7
5
8
*[FIX][Issue #15](https://github.com/nickmaccarthy/python-datemath/issues/15) - Fixed issue with parser finding invalid timeunits and throwing correct errors
A date math (aka datemath) parser compatiable with the elasticsearch 'date math' format
6
8
7
-
# Why?
8
-
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 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.
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.
12
+
13
+
## What is date math?
9
14
10
-
# What is date math ?
11
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.
If you want a Epoch timestamp back instead, we can do that.
147
+
136
148
```python
137
149
>>> dm('now+2d-1m', type='timestamp')
138
150
1453676321
139
151
```
140
152
141
-
# What timezone are my objects in?
142
-
By default all objects returned by datemath are in UTC. If you want them them in a different timezone, just pass along the ```tz``` argument.
143
-
Timezone list can be found here: https://gist.github.com/pamelafox/986163
144
-
```
145
-
from datemath import dm
153
+
## What timezone are my objects in?
154
+
155
+
By default all object returned by datemath are in UTC.
156
+
157
+
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
+
159
+
If you provide a timezone offset in your timestring, datemath will return your time object as that timezone offset in the string.
160
+
161
+
Note - currently timestrings with a timezone offset and the usage of the ```tz``` argument will result in the time object being returned with the timezone of what was in the timezone offset in the original string
162
+
163
+
```python
164
+
>>>from datemath import dm
165
+
>>>
146
166
>>> dm('now')
147
167
<Arrow [2016-01-26T01:00:53.601088+00:00]>
148
168
>>>
@@ -154,9 +174,26 @@ from datemath import dm
154
174
>>>
155
175
>>> dm('2017-10-20 09:15:20', tz='US/Pacific')
156
176
<Arrow [2017-10-20T09:15:20.000000-08:00]>
177
+
>>>
178
+
>>># Timestring with TZ offset in the string (ISO8601 format only)
179
+
>>> dm('2016-01-01T00:00:00-05:00')
180
+
<Arrow [2016-01-01T00:00:00-05:00]>
181
+
>>>
182
+
>>># Timestring with TZ offset with datemath added (again, TS must be in ISO8601)
183
+
>>> dm('2016-01-01T00:00:00-05:00||+2d+3h+5m')
184
+
<Arrow [2016-01-03T03:05:00-05:00]>
185
+
>>>
186
+
>>># Note, timestrings with TZ offsets will be returned as the timezone of the offset in the string even if the "tz" option is used.
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`.
:param type - if we are dealing with a arrow or datetime object
90
92
:param roundDown - wether or not we should round up or round down on this. default is roundDown=True, which means if it was 12:00:00, `/d` would be '00:00:00', and with roundDown=False, `/d` would be '29:59:59'
91
93
'''
94
+
ifdebug: print("parse() - starting for expression: {}".format(expression))
92
95
ifnowisNone:
96
+
ifdebug: print("parse() - Now is None, setting now to utcnow()")
0 commit comments