diff options
| author | Cedric Snauwaert <csn@openerp.com> | 2014-07-03 14:10:09 +0200 |
|---|---|---|
| committer | Cedric Snauwaert <csn@openerp.com> | 2014-08-25 12:11:17 +0200 |
| commit | 88dfd62aa539c5c2ad3e24be06c1ac7cffedd1a5 (patch) | |
| tree | ef1373ed8bb95d95c367947386b851801a1d5917 /addons/web/static/src/js/formats.js | |
| parent | d8ecb5781e7874e44decf10cafa73b53d05c6ebc (diff) | |
[FIX] web: remove old datetimepicker and change by bootstrap datetimepicker
Diffstat (limited to 'addons/web/static/src/js/formats.js')
| -rw-r--r-- | addons/web/static/src/js/formats.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/addons/web/static/src/js/formats.js b/addons/web/static/src/js/formats.js index 3d7b574e56a..14026f17681 100644 --- a/addons/web/static/src/js/formats.js +++ b/addons/web/static/src/js/formats.js @@ -361,4 +361,52 @@ instance.web.round_decimals = function(value, decimals){ return instance.web.round_precision(value, Math.pow(10,-decimals)); }; +/** ++ * ++ * convert python.strftime format into moment.js format ++ * inspired from : https://github.com/uruz/moment-datetime/blob/master/moment-datetime.js ++*/ +instance.web.convert_to_moment_format = function(format){ + if (!format) + return false; + var replacements = { + 'a': 'ddd', + 'A': 'dddd', + 'b': 'MMM', + 'B': 'MMMM', + //'c': //%c is defined too vaguely + 'd': 'DD', + //'f': JS have no support for microseconds and moment.js have no support for milliseconds + 'H': 'HH', + 'I': 'hh', + 'j': 'DDDD', + 'm': 'MM', + 'M': 'mm', + 'p': 'A', + 'S': 'ss', + 'U': 'ww',//ww is for Sunday-based week + 'w': 'd', + //'W': 'ww',//%W is weeknumber for weeks starting from Monday and it is not implemented in moment.js + //'x': + //'X': //%x and %X are defined too vaguely to be implemented + 'y': 'YY', + 'Y': 'YYYY', + 'z': 'ZZ', + //'Z': 'z', - moment.js does not support timezone names + '%': '%' + } + var moment_format = '', directive_index = 0, replacement, unformatted; + while (format.indexOf('%') !== -1){ + directive_index = format.indexOf('%') + 1; + replacement = replacements[format[directive_index]]; + unformatted = format.substr(0, directive_index-1); + if (unformatted.length){ + unformatted = '[' + unformatted.replace(/(\[|\])/g, '\\$&') +']'; + } + moment_format += unformatted + (replacement ? replacement : format[directive_index]); + format = format.substr(directive_index+1); + } + return moment_format; +}; + })(); |
