Repository: moment/luxon
Pull request #1121 (2022-01-18 21:26:11)

Add includeOffsetSpace option to toSQLTime and toSQL
Fixes https://github.com/moment/luxon/issues/941

linux-foundation-easycla[bot]: <a href="https://api.easycla.lfx.linuxfoundation.org/v2/repository-provider/github/sign/19772872/47118129/1121/#/?version=2"><img src="https://s3.amazonaws.com/cla-project-logo-prod/cla-not-signed.svg" alt="CLA Not Signed" align="left" height="28" width="328" ></a><br/><br /><ul><li><a href='https://api.easycla.lfx.linuxfoundation.org/v2/repository-provider/github/sign/19772872/47118129/1121/#/?version=2' target='_blank'>:x:</a> - Stuart Dotson The commit (717ae9f44d6b7fc357429d17e6c472f3ceaf2715) is not authorized under a signed CLA. <a href='https://api.easycla.lfx.linuxfoundation.org/v2/repository-provider/github/sign/19772872/47118129/1121/#/?version=2' target='_blank'>Please click here to be authorized</a>. For further assistance with EasyCLA, <a href='https://jira.linuxfoundation.org/servicedesk/customer/portal/4' target='_blank'>please submit a support request ticket</a>.</li></ul>

Patch:
diff --git a/src/datetime.js b/src/datetime.js
index 46e8e117..47acf7a7 100644
--- a/src/datetime.js
+++ b/src/datetime.js
@@ -1678,17 +1678,20 @@ export default class DateTime {
    * @param {Object} opts - options
    * @param {boolean} [opts.includeZone=false] - include the zone, such as 'America/New_York'. Overrides includeOffset.
    * @param {boolean} [opts.includeOffset=true] - include the offset, such as 'Z' or '-04:00'
+   * @param {boolean} [opts.includeOffsetSpace=true] - include the space between the time and the offset, such as '05:15:16.345 -04:00'
    * @example DateTime.utc().toSQL() //=> '05:15:16.345'
    * @example DateTime.now().toSQL() //=> '05:15:16.345 -04:00'
    * @example DateTime.now().toSQL({ includeOffset: false }) //=> '05:15:16.345'
    * @example DateTime.now().toSQL({ includeZone: false }) //=> '05:15:16.345 America/New_York'
    * @return {string}
    */
-  toSQLTime({ includeOffset = true, includeZone = false } = {}) {
+  toSQLTime({ includeOffset = true, includeZone = false, includeOffsetSpace = true } = {}) {
     let fmt = "HH:mm:ss.SSS";
 
     if (includeZone || includeOffset) {
-      fmt += " ";
+      if (includeOffsetSpace) {
+        fmt += " ";
+      }
       if (includeZone) {
         fmt += "z";
       } else if (includeOffset) {
@@ -1704,6 +1707,7 @@ export default class DateTime {
    * @param {Object} opts - options
    * @param {boolean} [opts.includeZone=false] - include the zone, such as 'America/New_York'. Overrides includeOffset.
    * @param {boolean} [opts.includeOffset=true] - include the offset, such as 'Z' or '-04:00'
+   * @param {boolean} [opts.includeOffsetSpace=true] - include the space between the time and the offset, such as '05:15:16.345 -04:00'
    * @example DateTime.utc(2014, 7, 13).toSQL() //=> '2014-07-13 00:00:00.000 Z'
    * @example DateTime.local(2014, 7, 13).toSQL() //=> '2014-07-13 00:00:00.000 -04:00'
    * @example DateTime.local(2014, 7, 13).toSQL({ includeOffset: false }) //=> '2014-07-13 00:00:00.000'
@@ -1749,6 +1753,14 @@ export default class DateTime {
   toSeconds() {
     return this.isValid ? this.ts / 1000 : NaN;
   }
+  
+  /**
+   * Returns the epoch seconds (as a whole number) of this DateTime.
+   * @return {number}
+   */
+  toUnixInteger() {
+    return this.isValid ? Math.floor(this.ts / 1000) : NaN;
+  }
 
   /**
    * Returns an ISO 8601 representation of this DateTime appropriate for use in JSON.


Test patch:
diff --git a/test/datetime/format.test.js b/test/datetime/format.test.js
index 2d4dd550..5cc76553 100644
--- a/test/datetime/format.test.js
+++ b/test/datetime/format.test.js
@@ -243,6 +243,12 @@ test("DateTime#toSQLTime() accepts an includeOffset option", () => {
   expect(dt.setZone("America/New_York").toSQLTime({ includeOffset: false })).toBe("05:23:54.123");
 });
 
+test("DateTime#toSQLTime() accepts an includeOffsetSpace option", () => {
+  expect(dt.setZone("America/New_York").toSQLTime({ includeOffsetSpace: false })).toBe(
+    "05:23:54.123-04:00"
+  );
+});
+
 test("DateTime#toSQLTime() accepts an includeZone option", () => {
   expect(dt.toUTC().toSQLTime({ includeZone: true })).toBe("09:23:54.123 UTC");
   expect(dt.setZone("America/New_York").toSQLTime({ includeZone: true })).toBe(
@@ -263,6 +269,12 @@ test("DateTime#toSQL() returns SQL date time", () => {
   expect(dt.setZone("America/New_York").toSQL()).toBe("1982-05-25 05:23:54.123 -04:00");
 });
 
+test("DateTime#toSQL() accepts space option", () => {
+  expect(dt.setZone("America/New_York").toSQL({ includeOffsetSpace: false })).toBe(
+    "1982-05-25 05:23:54.123-04:00"
+  );
+});
+
 test("DateTime#toSQL() accepts an includeOffset option", () => {
   expect(dt.toUTC().toSQL({ includeOffset: false })).toBe("1982-05-25 09:23:54.123");
   expect(dt.setZone("America/New_York").toSQL({ includeOffset: false })).toBe(