1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
6 # Copyright (C) 2010 OpenERP s.a. (<http://openerp.com>).
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU Affero General Public License as
10 # published by the Free Software Foundation, either version 3 of the
11 # License, or (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU Affero General Public License for more details.
18 # You should have received a copy of the GNU Affero General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
25 DEFAULT_SERVER_DATE_FORMAT = "%Y-%m-%d"
26 DEFAULT_SERVER_TIME_FORMAT = "%H:%M:%S"
27 DEFAULT_SERVER_DATETIME_FORMAT = "%s %s" % (
28 DEFAULT_SERVER_DATE_FORMAT,
29 DEFAULT_SERVER_TIME_FORMAT)
31 def parse_datetime(str):
33 Converts a string to a datetime object using OpenERP's
34 datetime string format (exemple: '2011-12-01 15:12:35').
36 No timezone information is added, the datetime is a naive instance, but
37 according to OpenERP 6.1 specification the timezone is always UTC.
41 return datetime.datetime.strptime(str, DEFAULT_SERVER_DATETIME_FORMAT)
45 Converts a string to a date object using OpenERP's
46 date string format (exemple: '2011-12-01').
50 return datetime.datetime.strptime(str, DEFAULT_SERVER_DATE_FORMAT).date()
54 Converts a string to a time object using OpenERP's
55 time string format (exemple: '15:12:35').
59 return datetime.datetime.strptime(str, DEFAULT_SERVER_TIME_FORMAT).time()
61 def format_datetime(obj):
63 Converts a datetime object to a string using OpenERP's
64 datetime string format (exemple: '2011-12-01 15:12:35').
66 The datetime instance should not have an attached timezone and be in UTC.
70 return obj.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
74 Converts a date object to a string using OpenERP's
75 date string format (exemple: '2011-12-01').
79 return obj.strftime(DEFAULT_SERVER_DATE_FORMAT)
83 Converts a time object to a string using OpenERP's
84 time string format (exemple: '15:12:35').
88 return obj.strftime(DEFAULT_SERVER_TIME_FORMAT)