From: Bill Erickson Date: Fri, 10 Mar 2017 18:55:09 +0000 (-0500) Subject: LP#1671904 egDate unit test handles time change X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=refs%2Fheads%2Fuser%2Fberick%2Flp1671904-egdate-unit-test-time-change;p=working%2FEvergreen.git 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 --- 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) {