changeset 4610:8661811abca3

Use the local timezone for query/retrieve in the Orthanc Explorer interface (was UTC before)
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 02 Apr 2021 13:50:56 +0200
parents c8f444e8556d
children dfb7429f0d48 57b1a36645ae
files NEWS OrthancServer/OrthancExplorer/query-retrieve.js
diffstat 2 files changed, 21 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Tue Mar 30 16:34:02 2021 +0200
+++ b/NEWS	Fri Apr 02 13:50:56 2021 +0200
@@ -8,6 +8,11 @@
 * New functions in the SDK:
   - OrthancPluginCallRestApi()
 
+Maintenance
+-----------
+
+* Use the local timezone for query/retrieve in the Orthanc Explorer interface (was UTC before)
+
 
 Version 1.9.1 (2021-02-25)
 ==========================
--- a/OrthancServer/OrthancExplorer/query-retrieve.js	Tue Mar 30 16:34:02 2021 +0200
+++ b/OrthancServer/OrthancExplorer/query-retrieve.js	Fri Apr 02 13:50:56 2021 +0200
@@ -31,18 +31,25 @@
  **/
 
 
-function JavascriptDateToDicom(date)
-{
-  var s = date.toISOString();
-  return s.substring(0, 4) + s.substring(5, 7) + s.substring(8, 10);
-}
-
 function GenerateDicomDate(days)
 {
   var today = new Date();
-  var other = new Date(today);
-  other.setDate(today.getDate() + days);
-  return JavascriptDateToDicom(other);
+  var utc = new Date(today);
+  utc.setDate(today.getDate() + days);
+
+  /**
+   * "utc" contains the date of interest, as selected by the user.
+   * Calling "utc.toISOString()" would return a date in the UTC
+   * timezone, whereas the user expects the date to be expressed in
+   * her own timezone. We thus adjust from UTC to the local timezome.
+   * https://stackoverflow.com/a/50537435
+   * https://groups.google.com/g/orthanc-users/c/dK7EEPVpedk/m/DPtMRFnKAgAJ
+   **/
+  var timezoneOffset = today.getTimezoneOffset() * 60 * 1000;
+  var localDate = new Date(utc.getTime() - timezoneOffset);
+  
+  var s = localDate.toISOString();
+  return s.substring(0, 4) + s.substring(5, 7) + s.substring(8, 10);
 }