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: README.md
+35-21Lines changed: 35 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -3,31 +3,35 @@
3
3
# Python Datemath
4
4
5
5
## What?
6
+
6
7
A date math (aka datemath) parser compatiable with the elasticsearch 'date math' format
7
8
8
9
## Why?
9
-
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.
10
10
11
-
## What is date math ?
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?
14
+
12
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
+
137
148
```python
138
149
>>> dm('now+2d-1m', type='timestamp')
139
150
1453676321
140
151
```
141
152
142
153
## What timezone are my objects in?
154
+
143
155
By default all object returned by datemath are in UTC.
144
156
145
-
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
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)
146
158
147
159
If you provide a timezone offset in your timestring, datemath will return your time object as that timezone offset in the string.
148
160
149
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
150
-
```
162
+
163
+
```python
151
164
>>>from datemath import dm
152
165
>>>
153
166
>>> dm('now')
@@ -166,20 +179,21 @@ Note - currently timestrings with a timezone offset and the usage of the ```tz``
166
179
>>> dm('2016-01-01T00:00:00-05:00')
167
180
<Arrow [2016-01-01T00:00:00-05:00]>
168
181
>>>
169
-
>>> # Timestring with TZooffset with datemath added (again, TS must be in ISO8601)
182
+
>>># Timestring with TZ offset with datemath added (again, TS must be in ISO8601)
170
183
>>> dm('2016-01-01T00:00:00-05:00||+2d+3h+5m')
171
184
<Arrow [2016-01-03T03:05:00-05:00]>
172
185
>>>
173
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`.
0 commit comments