2
openerp.l10n_mn_base = function(openerp) {
4
* Converts a string to a Date javascript object using OpenERP's
5
* datetime string format (exemple: '2011-12-01 15:12:35').
7
* The time zone is assumed to be UTC (standard for OpenERP 6.1)
8
* and will be converted to the browser's time zone.
10
* @param {String} str A string representing a datetime.
13
openerp.web.str_to_datetime = function(str) {
17
var regex = /^(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(?:\.\d+)?$/;
18
var res = regex.exec(str);
20
throw new Error("'" + str + "' is not a valid datetime");
23
return new Date(Date.UTC(
25
parseInt(res[2], 10) - 1,
34
parseInt(res[2], 10) - 1,
43
* Converts a string to a Date javascript object using OpenERP's
44
* date string format (exemple: '2011-12-01').
46
* As a date is not subject to time zones, we assume it should be
47
* represented as a Date javascript object at 00:00:00 in the
48
* time zone of the browser.
50
* @param {String} str A string representing a date.
53
openerp.web.str_to_date = function(str) {
57
var regex = /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
58
var res = regex.exec(str);
60
throw new Error("'" + str + "' is not a valid date");
64
parseInt(res[2], 10) - 1,
70
* Converts a string to a Date javascript object using OpenERP's
71
* time string format (exemple: '15:12:35').
73
* The OpenERP times are supposed to always be naive times. We assume it is
74
* represented using a javascript Date with a date 1 of January 1970 and a
75
* time corresponding to the meant time in the browser's time zone.
77
* @param {String} str A string representing a time.
80
openerp.web.str_to_time = function(str) {
84
var regex = /^(\d\d):(\d\d):(\d\d)(?:\.\d+)?$/;
85
var res = regex.exec(str);
87
throw new Error("'" + str + "' is not a valid time");
90
1970, 0, 1, parseInt(res[1], 10), parseInt(res[2], 10), parseInt(res[3], 10));
94
* Left-pad provided arg 1 with zeroes until reaching size provided by second
97
* @param {Number|String} str value to pad
98
* @param {Number} size size to reach on the final padded value
99
* @returns {String} padded string
101
var zpad = function(str, size) {
103
return new Array(size - str.length + 1).join('0') + str;
107
* Converts a Date javascript object to a string using OpenERP's
108
* datetime string format (exemple: '2011-12-01 15:12:35').
110
* The time zone of the Date object is assumed to be the one of the
111
* browser and it will be converted to UTC (standard for OpenERP 6.1).
114
* @returns {String} A string representing a datetime.
116
openerp.web.datetime_to_str = function(obj) {
121
return zpad(obj.getUTCFullYear(),4) + "-" + zpad(obj.getUTCMonth() + 1,2) + "-"
122
+ zpad(obj.getUTCDate(),2) + " " + zpad(obj.getUTCHours(),2) + ":"
123
+ zpad(obj.getUTCMinutes(),2) + ":" + zpad(obj.getUTCSeconds(),2);
125
return zpad(obj.getFullYear(),4) + "-" + zpad(obj.getMonth() + 1,2) + "-"
126
+ zpad(obj.getDate(),2) + " " + zpad(obj.getHours(),2) + ":"
127
+ zpad(obj.getMinutes(),2) + ":" + zpad(obj.getSeconds(),2);
131
* Converts a Date javascript object to a string using OpenERP's
132
* date string format (exemple: '2011-12-01').
134
* As a date is not subject to time zones, we assume it should be
135
* represented as a Date javascript object at 00:00:00 in the
136
* time zone of the browser.
139
* @returns {String} A string representing a date.
141
openerp.web.date_to_str = function(obj) {
145
return zpad(obj.getFullYear(),4) + "-" + zpad(obj.getMonth() + 1,2) + "-"
146
+ zpad(obj.getDate(),2);
150
* Converts a Date javascript object to a string using OpenERP's
151
* time string format (exemple: '15:12:35').
153
* The OpenERP times are supposed to always be naive times. We assume it is
154
* represented using a javascript Date with a date 1 of January 1970 and a
155
* time corresponding to the meant time in the browser's time zone.
158
* @returns {String} A string representing a time.
160
openerp.web.time_to_str = function(obj) {
164
return zpad(obj.getHours(),2) + ":" + zpad(obj.getMinutes(),2) + ":"
165
+ zpad(obj.getSeconds(),2);