diff --git a/addons/base/static/src/js/dates.js b/addons/base/static/src/js/dates.js index da4e948e282..43656fd0ed8 100644 --- a/addons/base/static/src/js/dates.js +++ b/addons/base/static/src/js/dates.js @@ -1,6 +1,16 @@ openerp.base.dates = function(openerp) { +/** + * Converts a string to a Date javascript object using OpenERP's + * datetime string format (exemple: '2011-12-01 15:12:35'). + * + * The timezone is assumed to be UTC (standard for OpenERP 6.1) + * and will be converted to the browser's timezone. + * + * @param {String} str A string representing a datetime. + * @returns {Date} + */ openerp.base.parse_datetime = function(str) { if(!str) { return str; @@ -17,6 +27,13 @@ openerp.base.parse_datetime = function(str) { return obj; }; +/** + * Converts a string to a Date javascript object using OpenERP's + * date string format (exemple: '2011-12-01'). + * + * @param {String} str A string representing a date. + * @returns {Date} + */ openerp.base.parse_date = function(str) { if(!str) { return str; @@ -33,6 +50,13 @@ openerp.base.parse_date = function(str) { return obj; }; +/** + * Converts a string to a Date javascript object using OpenERP's + * time string format (exemple: '15:12:35'). + * + * @param {String} str A string representing a time. + * @returns {Date} + */ openerp.base.parse_time = function(str) { if(!str) { return str; @@ -49,7 +73,7 @@ openerp.base.parse_time = function(str) { return obj; }; -/** +/* * Just a simple function to add some '0' if an integer it too small. */ var fts = function(str, size) { @@ -61,6 +85,16 @@ var fts = function(str, size) { return to_add + str; }; +/** + * Converts a Date javascript object to a string using OpenERP's + * datetime string format (exemple: '2011-12-01 15:12:35'). + * + * The timezone of the Date object is assumed to be the one of the + * browser and it will be converted to UTC (standard for OpenERP 6.1). + * + * @param {Date} obj + * @returns {String} A string representing a datetime. + */ openerp.base.format_datetime = function(obj) { if(! str) { return false; @@ -70,6 +104,13 @@ openerp.base.format_datetime = function(obj) { + fts(obj.getUTCMinutes(),2) + ":" + fts(obj.getUTCSeconds(),2); }; +/** + * Converts a Date javascript object to a string using OpenERP's + * date string format (exemple: '2011-12-01'). + * + * @param {Date} obj + * @returns {String} A string representing a date. + */ openerp.base.format_date = function(obj) { if(! str) { return false; @@ -78,6 +119,13 @@ openerp.base.format_date = function(obj) { + fts(obj.getDate(),2); }; +/** + * Converts a Date javascript object to a string using OpenERP's + * time string format (exemple: '15:12:35'). + * + * @param {Date} obj + * @returns {String} A string representing a time. + */ openerp.base.format_time = function(obj) { if(! str) { return false;