Intuitive date formatting.
Project description
hotdate [![Build Status](https://travis-ci.org/mansam/hotdate.png?branch=master)](https://travis-ci.org/mansam/hotdate)
=======
`hotdate` is a library for doing friendly date formating. Its API is inspired by [Moment.js](http://momentjs.com).
`hotdate` wraps Python's builtin `datetime` object with a layer that simplifies some common operations that are annoying to do with `datetime`. More importantly, `hotdate` provides functionality for doing friendly/human-readable relative date formatting. It even has one of those crazy "fluent interfaces" that are so hip with the kids these days.
## A quick tour
### Construction
You can create hotdate objects in a bunch of ways.
```python
from hotdate import hotdate
# get the current time and date
>>> hotdate()
hotdate(2014, 3, 4, 21, 34, 3, 661600)
```
```python
>>> hotdate(2011)
hotdate(2011, 1, 1, 0, 0)
```
```python
>>> hotdate('2012 03', '%Y %m')
hotdate(2012, 3, 1, 0, 0)
```
```python
>>> d = datetime.datetime.now()
>>> hotdate(d)
hotdate(2014, 3, 4, 21, 34, 3, 661600)
```
### Formatting
You can use it to format dates:
```python
>>> hotdate().format()
'2014-03-04T21:46:18'
```
```python
>>> hotdate().format('%c')
'Tue Mar 4 21:47:03 2014'
```
### "How long ago?"
```python
>>> hotdate().from_now()
'just now'
```
```python
>>> hotdate(2011).from_now()
'2 years ago'
```
```python
>>> hotdate().add(minutes=30).from_now()
'29 minutes from now'
```
### Calendar date formatting
```python
>>> hotdate().calendar()
'Today at 09:50PM'
```
```python
>>> hotdate().add(days=1).calendar()
'Tomorrow at 09:51PM'
```
```python
>>> hotdate().subtract(days=4).calendar()
'Last Friday at 09:51PM'
```
```python
>>> hotdate(2011).calendar()
'1/1/2011'
```
### Use it just like a datetime
```python
>>> hotdate().isoformat()
'2014-03-05T17:00:28.699772'
```
```python
>>> hotdate.fromtimestamp(1311218002)
hotdate(2011, 7, 20, 23, 13, 22)
```
```python
>>> hotdate().timetuple()
time.struct_time(tm_year=2014, tm_mon=3, tm_mday=5, tm_hour=17, tm_min=10, tm_sec=35, tm_wday=2, tm_yday=64, tm_isdst=-1)
```
=======
`hotdate` is a library for doing friendly date formating. Its API is inspired by [Moment.js](http://momentjs.com).
`hotdate` wraps Python's builtin `datetime` object with a layer that simplifies some common operations that are annoying to do with `datetime`. More importantly, `hotdate` provides functionality for doing friendly/human-readable relative date formatting. It even has one of those crazy "fluent interfaces" that are so hip with the kids these days.
## A quick tour
### Construction
You can create hotdate objects in a bunch of ways.
```python
from hotdate import hotdate
# get the current time and date
>>> hotdate()
hotdate(2014, 3, 4, 21, 34, 3, 661600)
```
```python
>>> hotdate(2011)
hotdate(2011, 1, 1, 0, 0)
```
```python
>>> hotdate('2012 03', '%Y %m')
hotdate(2012, 3, 1, 0, 0)
```
```python
>>> d = datetime.datetime.now()
>>> hotdate(d)
hotdate(2014, 3, 4, 21, 34, 3, 661600)
```
### Formatting
You can use it to format dates:
```python
>>> hotdate().format()
'2014-03-04T21:46:18'
```
```python
>>> hotdate().format('%c')
'Tue Mar 4 21:47:03 2014'
```
### "How long ago?"
```python
>>> hotdate().from_now()
'just now'
```
```python
>>> hotdate(2011).from_now()
'2 years ago'
```
```python
>>> hotdate().add(minutes=30).from_now()
'29 minutes from now'
```
### Calendar date formatting
```python
>>> hotdate().calendar()
'Today at 09:50PM'
```
```python
>>> hotdate().add(days=1).calendar()
'Tomorrow at 09:51PM'
```
```python
>>> hotdate().subtract(days=4).calendar()
'Last Friday at 09:51PM'
```
```python
>>> hotdate(2011).calendar()
'1/1/2011'
```
### Use it just like a datetime
```python
>>> hotdate().isoformat()
'2014-03-05T17:00:28.699772'
```
```python
>>> hotdate.fromtimestamp(1311218002)
hotdate(2011, 7, 20, 23, 13, 22)
```
```python
>>> hotdate().timetuple()
time.struct_time(tm_year=2014, tm_mon=3, tm_mday=5, tm_hour=17, tm_min=10, tm_sec=35, tm_wday=2, tm_yday=64, tm_isdst=-1)
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
hotdate-0.4.2.tar.gz
(4.9 kB
view hashes)