Project

General

Profile

« Previous | Next » 

Revision 111

xml_func.py: Added support for decimal years (with day as the fraction)

View differences:

xml_func.py
1 1
# XML "function" nodes that evaluate their contents to text
2 2

  
3
import datetime
4

  
3 5
import xml_dom
4 6

  
5 7
def map_items(func, items):
......
19 21

  
20 22
def date(items):
21 23
    items = dict(items)
22
    return '-'.join([items['year'], items.get('month', '1'),
23
        items.get('day', '1')])
24
    year = float(items['year'])
25
    date = datetime.date(int(year), int(items.get('month', '1')),
26
        int(items.get('day', '1'))) + datetime.timedelta(round((year % 1.)*365))
27
    return date.strftime('%Y-%m-%d')
24 28

  
25 29
def name(items):
26 30
    items = dict(items)

Also available in: Unified diff