You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
3.1 KiB

10 years ago
  1. //-*- coding: utf-8 -*-
  2. //############################################################################
  3. //
  4. // OpenERP, Open Source Management Solution
  5. // This module copyright (C) 2014 Therp BV (<http://therp.nl>).
  6. //
  7. // This program is free software: you can redistribute it and/or modify
  8. // it under the terms of the GNU Affero General Public License as
  9. // published by the Free Software Foundation, either version 3 of the
  10. // License, or (at your option) any later version.
  11. //
  12. // This program is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU Affero General Public License for more details.
  16. //
  17. // You should have received a copy of the GNU Affero General Public License
  18. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. //
  20. //############################################################################
  21. openerp.testing.section(
  22. 'timezones',
  23. {dependencies: ['web.coresetup', 'web.pyeval']},
  24. function(test)
  25. {
  26. test('basic', function(instance)
  27. {
  28. openerp.web_pytz(instance);
  29. var eval = function(expression, context)
  30. {
  31. var result_domain = instance.web.pyeval.eval(
  32. 'domain', "[['a', '=', " + expression + "]]",
  33. context || {}, {});
  34. return result_domain[0][2];
  35. }
  36. var result;
  37. result = eval(
  38. "pytz.timezone('Europe/Amsterdam').localize(datetime.datetime(2014, 10, 6, 0, 0, 0)).astimezone(pytz.timezone('utc')).strftime('%Y-%m-%d %H:%M:%S')");
  39. ok(result == '2014-10-05 22:00:00', 'day start in Amsterdam, summer');
  40. result = eval(
  41. "pytz.timezone('Europe/Amsterdam').localize(datetime.datetime(2014, 12, 6, 0, 0, 0)).astimezone(pytz.timezone('utc')).strftime('%Y-%m-%d %H:%M:%S')");
  42. ok(result == '2014-12-05 23:00:00', 'day start in Amsterdam, winter');
  43. result = eval(
  44. "pytz.timezone('America/Toronto').localize(datetime.datetime(2014, 10, 6, 0, 0, 0)).astimezone(pytz.utc).strftime('%Y-%m-%d %H:%M:%S')");
  45. ok(result == '2014-10-06 04:00:00', 'day start in Torronto');
  46. result = eval(
  47. "pytz.timezone('Asia/Shanghai').localize(datetime.datetime(2014, 10, 6, 0, 0, 0)).astimezone(pytz.utc).strftime('%Y-%m-%d %H:%M:%S')");
  48. ok(result == '2014-10-05 16:00:00', 'day start in Shanghai');
  49. _.each(['Europe/Amsterdam', 'America/Toronto', 'Asia/Shanghai'], function(tz)
  50. {
  51. result = eval("utc_today().strftime('%Y-%m-%d %H:%M:%S')", {tz: tz});
  52. var now = moment();
  53. ok(result == moment.tz([now.year(), now.month(), now.date()], tz).hour(0).utc().format('YYYY-MM-DD HH:mm:ss'), _.str.sprintf('day start with shortcut in %s', tz));
  54. });
  55. });
  56. });