From 482c98453d97bec172c7b0a201baa2b81c0c97dc Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 10 Mar 2017 13:55:09 -0500 Subject: [PATCH] LP#1671904 egDate unit test handles time change Teach the egDate unit test requesting '2 days' worth of seconds to allow values for 47, 48, or 49 hours. 47 and 49 happen when crossing time change boundaries. Signed-off-by: Bill Erickson Signed-off-by: Kathy Lussier --- .../web/js/ui/default/staff/services/date.js | 2 +- .../js/ui/default/staff/test/unit/egDate.js | 28 ++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Open-ILS/web/js/ui/default/staff/services/date.js b/Open-ILS/web/js/ui/default/staff/services/date.js index 629b799785..781b4c495a 100644 --- a/Open-ILS/web/js/ui/default/staff/services/date.js +++ b/Open-ILS/web/js/ui/default/staff/services/date.js @@ -14,7 +14,7 @@ angular.module('egCoreMod') * Converts an interval string to seconds. * * egDate.intervalToSeconds('1 min 2 seconds')) => 62 - * egDate.intervalToSeconds('2 days')) => 172800 + * egDate.intervalToSeconds('2 days')) => 172800 (except across time changes) * egDate.intervalToSeconds('02:00:23')) => 7223 */ service.intervalToSeconds = function(interval) { diff --git a/Open-ILS/web/js/ui/default/staff/test/unit/egDate.js b/Open-ILS/web/js/ui/default/staff/test/unit/egDate.js index f55fe9f2dd..5802e2d90c 100644 --- a/Open-ILS/web/js/ui/default/staff/test/unit/egDate.js +++ b/Open-ILS/web/js/ui/default/staff/test/unit/egDate.js @@ -3,8 +3,34 @@ describe('egDate', function(){ beforeEach(module('egCoreMod')); + beforeEach(function () { + this.addMatchers({ + + // "2 days" may be 47, 48, or 49 hours depending on the + // proximity to and direction of a time change event. + // This does not take leap seconds into account. + toBe2DaysOfSeconds: function () { + var actual = this.actual; + var hours_47 = 169200; + var hours_48 = 172800; + var hours_49 = 176400; + + this.message = function () { + return "Expected " + actual + " to be " + + hours_47 + ", " + hours_48 + ", or " + hours_49; + }; + + return ( + actual == hours_47 || + actual == hours_48 || + actual == hours_49 + ); + } + }); + }); + it('should parse a simple interval', inject(function(egDate) { - expect(egDate.intervalToSeconds('2 days')).toBe(172800); + expect(egDate.intervalToSeconds('2 days')).toBe2DaysOfSeconds(); })); it('should parse a combined interval', inject(function(egDate) { -- 2.43.2