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.

76 lines
3.4 KiB

  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. 'python_compatibility',
  23. {dependencies: ['web.coresetup', 'web.pyeval']},
  24. function(test)
  25. {
  26. test('basic deltas', function(instance)
  27. {
  28. openerp.web_relativedelta(instance);
  29. var eval = function(expression)
  30. {
  31. var result_domain = instance.web.pyeval.eval(
  32. 'domain', "[['a', '=', " + expression + "]]", {}, {});
  33. return result_domain[0][2];
  34. }
  35. var result;
  36. result = eval(
  37. "(datetime.date(2012, 12, 25) + relativedelta(days=7)).strftime('%Y-%m-%d')");
  38. ok(result == '2013-01-01', "cross year");
  39. result = eval(
  40. //2012 is a leap year
  41. "(datetime.date(2012, 01, 01) + relativedelta(days=366)).strftime('%Y-%m-%d')");
  42. ok(result == '2013-01-01', "cross leap year");
  43. result = eval(
  44. "(datetime.date(2012, 02, 01) + relativedelta(day=366)).strftime('%Y-%m-%d')");
  45. ok(result == '2012-02-29', "absolute day");
  46. result = eval(
  47. "(datetime.date(2012, 02, 01) + relativedelta(hours=-1)).strftime('%Y-%m-%d')");
  48. ok(result == '2012-01-31', "negative hour");
  49. result = eval(
  50. "(datetime.date(2012, 01, 30) + relativedelta(weekday=0)).strftime('%Y-%m-%d')");
  51. ok(result == '2012-01-30', "weekday=MO (on monday)");
  52. result = eval(
  53. "(datetime.date(2012, 01, 31) + relativedelta(weekday=0)).strftime('%Y-%m-%d')");
  54. ok(result == '2012-02-06', "weekday=MO (on tuesday)");
  55. result = eval(
  56. "(datetime.date(2012, 01, 30) + relativedelta(weeks=-1, days=1, weekday=0)).strftime('%Y-%m-%d')");
  57. ok(result == '2012-01-30', "last monday (on monday)");
  58. result = eval(
  59. "(datetime.date(2012, 01, 31) + relativedelta(weeks=-1, days=1, weekday=0)).strftime('%Y-%m-%d')");
  60. ok(result == '2012-01-30', "last monday (on tuesday)");
  61. result = eval(
  62. "(datetime.date(2012, 02, 01) + relativedelta(weeks=-1, days=1, weekday=0)).strftime('%Y-%m-%d')");
  63. ok(result == '2012-01-30', "last monday (on wednesday)");
  64. });
  65. });