Repository: moment/luxon
Pull request #1199 (2022-05-07 02:11:50)

fix bug 908 isInDST() incorrect
this fix the bug for DateTime.isInDST() returns False when it should return True.

 specifically for the year 1974 in USA.

from January 1974 to end of October 1974, USA was in DST

this is a very special problem that is not really fixable with an elegant algorithm.

this is my proposition (far from perfect). let me know what you think about it. 

hawkett: An alternative could be to just check explicitly against Jan 1 in all circumstances (rather than solving for just USA in 1974) - e.g. just add `day: 1`:

```
return (
    this.offset > this.set({ month: 1, day: 1 }).offset || this.offset > this.set({ month: 5 }).offset
);
```

The existing method checks a random day in January, while this approach just forces that day to be consistently the 1st of January. This has the advantage of capturing other possible occurrences, past and future.
socraticDevBlog: omg!  thanks @hawkett 

Patch:
diff --git a/site/demo/demo.js b/site/demo/demo.js
index 20af69dd..b3a84bf9 100644
--- a/site/demo/demo.js
+++ b/site/demo/demo.js
@@ -19,6 +19,8 @@ function demo(luxon) {
         return "[ DateTime " + result.toISO() + " ]";
       case result instanceof Duration:
         return "[ Duration " + JSON.stringify(result.toObject()) + " ]";
+      case result instanceof Date:
+        return "[ Date " + result.toString() + " ]";
       default:
         return JSON.stringify(result);
     }
@@ -37,18 +39,23 @@ function demo(luxon) {
 
   example("Info.features()");
   example("DateTime.now()");
-  example("DateTime.local(2017, 5, 15, 17, 36)");
+  example("DateTime.now().toUnixInteger()");
+  example("DateTime.now().toJSDate()");
+  example("DateTime.utc().toISO()");
   example("DateTime.utc(2017, 5, 15, 17, 36)");
-  example("DateTime.now().toUTC()");
   example("DateTime.utc(2017, 5, 15, 17, 36).toLocal()");
+  example("DateTime.local(2017, 5, 15, 17, 36)");
+  example("DateTime.local(2017, 5, 15, 17, 36).toUTC()");
   example("DateTime.now().toObject()");
-  example("DateTime.fromObject({year: 2017, month: 5, day: 15, hour: 17, minute: 36})");
+  example("DateTime.fromObject({ year: 2017, month: 5, day: 15, hour: 17, minute: 36 })");
   example(
-    "DateTime.fromObject({year: 2017, month: 5, day: 15, hour: 17, minute: 36 }, { zone: 'America/New_York' })"
+    "DateTime.fromObject({ year: 2017, month: 5, day: 15, hour: 17, minute: 36 }, { zone: 'America/New_York' })"
   );
   example(
-    "DateTime.fromObject({year: 2017, month: 5, day: 15, hour: 17, minute: 36 }, { zone: 'Asia/Singapore' })"
+    "DateTime.fromObject({ year: 2017, month: 5, day: 15, hour: 17, minute: 36 }, { zone: 'Asia/Singapore' })"
   );
+  example("DateTime.now().setZone('America/New_York')");
+  example("DateTime.now().setZone('America/New_York').startOf('day')");
   example("DateTime.now().plus({minutes: 15, seconds: 8})");
   example("DateTime.now().plus({days: 6})");
   example("DateTime.now().minus({days: 6})");
diff --git a/src/datetime.js b/src/datetime.js
index 0c880c79..f91aff4b 100644
--- a/src/datetime.js
+++ b/src/datetime.js
@@ -1198,7 +1198,8 @@ export default class DateTime {
       return false;
     } else {
       return (
-        this.offset > this.set({ month: 1 }).offset || this.offset > this.set({ month: 5 }).offset
+        this.offset > this.set({ month: 1, day: 1 }).offset ||
+        this.offset > this.set({ month: 5 }).offset
       );
     }
   }
diff --git a/src/impl/tokenParser.js b/src/impl/tokenParser.js
index 781ef42c..70234c41 100644
--- a/src/impl/tokenParser.js
+++ b/src/impl/tokenParser.js
@@ -13,7 +13,7 @@ function intUnit(regex, post = (i) => i) {
 }
 
 const NBSP = String.fromCharCode(160);
-const spaceOrNBSP = `( |${NBSP})`;
+const spaceOrNBSP = `[ ${NBSP}]`;
 const spaceOrNBSPRegExp = new RegExp(spaceOrNBSP, "g");
 
 function fixListRegex(s) {


Test patch:
diff --git a/test/datetime/zone.test.js b/test/datetime/zone.test.js
index c757b147..fbb7e45d 100644
--- a/test/datetime/zone.test.js
+++ b/test/datetime/zone.test.js
@@ -231,6 +231,12 @@ test("DateTime#isInDST() returns false for post-DST times", () => {
   expect(zoned.set({ month: 12 }).isInDST).toBe(false);
 });
 
+test("DateTime#isInDST() returns true for 1974 whole year in USA- from January 6th to October 27th", () => {
+  const zoned = dt().setZone("America/Los_Angeles");
+  expect(zoned.set({ year: 1974, month: 1, day: 6 }).isInDST).toBe(true);
+  expect(zoned.set({ year: 1974, month: 10, day: 27 }).isInDST).toBe(false);
+});
+
 //------
 // #invalid
 //------