LP#1671904 egDate unit test handles time change
authorBill Erickson <berickxx@gmail.com>
Fri, 10 Mar 2017 18:55:09 +0000 (13:55 -0500)
committerKathy Lussier <klussier@masslnc.org>
Sat, 11 Mar 2017 04:26:59 +0000 (23:26 -0500)
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 <berickxx@gmail.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/web/js/ui/default/staff/services/date.js
Open-ILS/web/js/ui/default/staff/test/unit/egDate.js

index 629b799..781b4c4 100644 (file)
@@ -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) {
index f55fe9f..5802e2d 100644 (file)
@@ -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) {