# HG changeset patch # User Sebastien Jodogne # Date 1519055705 -3600 # Node ID 8cc3ca64a534dc8a161cb875835c094c21d485bb # Parent 0c57f40e2fbfcd6fa6db463b5793dc3f90155c5d Orthanc now uses UTC (universal time) instead of local time in its database diff -r 0c57f40e2fbf -r 8cc3ca64a534 Core/DicomParsing/DicomDirWriter.cpp --- a/Core/DicomParsing/DicomDirWriter.cpp Thu Feb 08 11:51:41 2018 +0100 +++ b/Core/DicomParsing/DicomDirWriter.cpp Mon Feb 19 16:55:05 2018 +0100 @@ -128,6 +128,7 @@ class DicomDirWriter::PImpl { private: + bool utc_; std::string fileSetId_; bool extendedSopClass_; TemporaryFile file_; @@ -259,11 +260,23 @@ public: PImpl() : + utc_(true), // By default, use UTC (universal time, not local time) fileSetId_("ORTHANC_MEDIA"), extendedSopClass_(false) { } + + bool IsUtcUsed() const + { + return utc_; + } + + void SetUtcUsed(bool utc) + { + utc_ = utc; + } + void EnableExtendedSopClass(bool enable) { if (enable) @@ -297,7 +310,7 @@ // cf. "DicomDirInterface::buildStudyRecord()" std::string nowDate, nowTime; - SystemToolbox::GetNowDicom(nowDate, nowTime); + SystemToolbox::GetNowDicom(nowDate, nowTime, utc_); std::string studyDate; if (!GetUtf8TagValue(studyDate, dicom, encoding, DCM_StudyDate) && @@ -496,6 +509,16 @@ } } + void DicomDirWriter::SetUtcUsed(bool utc) + { + pimpl_->SetUtcUsed(utc); + } + + bool DicomDirWriter::IsUtcUsed() const + { + return pimpl_->IsUtcUsed(); + } + void DicomDirWriter::SetFileSetId(const std::string& id) { pimpl_->SetFileSetId(id); diff -r 0c57f40e2fbf -r 8cc3ca64a534 Core/DicomParsing/DicomDirWriter.h --- a/Core/DicomParsing/DicomDirWriter.h Thu Feb 08 11:51:41 2018 +0100 +++ b/Core/DicomParsing/DicomDirWriter.h Mon Feb 19 16:55:05 2018 +0100 @@ -50,6 +50,10 @@ ~DicomDirWriter(); + void SetUtcUsed(bool utc); + + bool IsUtcUsed() const; + void SetFileSetId(const std::string& id); void Add(const std::string& directory, diff -r 0c57f40e2fbf -r 8cc3ca64a534 Core/SystemToolbox.cpp --- a/Core/SystemToolbox.cpp Thu Feb 08 11:51:41 2018 +0100 +++ b/Core/SystemToolbox.cpp Mon Feb 19 16:55:05 2018 +0100 @@ -561,17 +561,30 @@ } - std::string SystemToolbox::GetNowIsoString() + static boost::posix_time::ptime GetNow(bool utc) { - boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); - return boost::posix_time::to_iso_string(now); + if (utc) + { + return boost::posix_time::second_clock::universal_time(); + } + else + { + return boost::posix_time::second_clock::local_time(); + } + } + + + std::string SystemToolbox::GetNowIsoString(bool utc) + { + return boost::posix_time::to_iso_string(GetNow(utc)); } void SystemToolbox::GetNowDicom(std::string& date, - std::string& time) + std::string& time, + bool utc) { - boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); + boost::posix_time::ptime now = GetNow(utc); tm tm = boost::posix_time::to_tm(now); char s[32]; diff -r 0c57f40e2fbf -r 8cc3ca64a534 Core/SystemToolbox.h --- a/Core/SystemToolbox.h Thu Feb 08 11:51:41 2018 +0100 +++ b/Core/SystemToolbox.h Mon Feb 19 16:55:05 2018 +0100 @@ -95,9 +95,10 @@ std::string GenerateUuid(); - std::string GetNowIsoString(); + std::string GetNowIsoString(bool utc); void GetNowDicom(std::string& date, - std::string& time); + std::string& time, + bool utc); } } diff -r 0c57f40e2fbf -r 8cc3ca64a534 NEWS --- a/NEWS Thu Feb 08 11:51:41 2018 +0100 +++ b/NEWS Mon Feb 19 16:55:05 2018 +0100 @@ -5,6 +5,9 @@ -------- * "/system" URI returns the version of the Orthanc REST API +* "/tools/now" returns the current UTC (universal) time +* "/tools/now-local" returns the curent local time. + This was the behavior of "/tools/now" until release 1.3.1. * Added "?expand" GET argument to "/peers" and "/modalities" routes * New URI: "/tools/create-media-extended" to generate a DICOMDIR archive from several resources, including additional type-3 tags @@ -12,6 +15,7 @@ Maintenance ----------- +* Orthanc now uses UTC (universal time) instead of local time in its database * Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005) * Upgrade to curl 7.57.0 for static and Windows builds * Support of Linux Standard Base diff -r 0c57f40e2fbf -r 8cc3ca64a534 OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp Thu Feb 08 11:51:41 2018 +0100 +++ b/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp Mon Feb 19 16:55:05 2018 +0100 @@ -831,7 +831,7 @@ // Inject time-related information std::string date, time; - SystemToolbox::GetNowDicom(date, time); + SystemToolbox::GetNowDicom(date, time, true /* use UTC time (not local time) */); dicom.ReplacePlainString(DICOM_TAG_ACQUISITION_DATE, date); dicom.ReplacePlainString(DICOM_TAG_ACQUISITION_TIME, time); dicom.ReplacePlainString(DICOM_TAG_CONTENT_DATE, date); diff -r 0c57f40e2fbf -r 8cc3ca64a534 OrthancServer/OrthancRestApi/OrthancRestSystem.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestSystem.cpp Thu Feb 08 11:51:41 2018 +0100 +++ b/OrthancServer/OrthancRestApi/OrthancRestSystem.cpp Mon Feb 19 16:55:05 2018 +0100 @@ -131,9 +131,10 @@ call.GetOutput().AnswerBuffer(result, "text/plain"); } + template static void GetNowIsoString(RestApiGetCall& call) { - call.GetOutput().AnswerBuffer(SystemToolbox::GetNowIsoString(), "text/plain"); + call.GetOutput().AnswerBuffer(SystemToolbox::GetNowIsoString(UTC), "text/plain"); } @@ -274,7 +275,8 @@ Register("/statistics", GetStatistics); Register("/tools/generate-uid", GenerateUid); Register("/tools/execute-script", ExecuteScript); - Register("/tools/now", GetNowIsoString); + Register("/tools/now", GetNowIsoString); + Register("/tools/now-local", GetNowIsoString); Register("/tools/dicom-conformance", GetDicomConformanceStatement); Register("/tools/default-encoding", GetDefaultEncoding); Register("/tools/default-encoding", SetDefaultEncoding); diff -r 0c57f40e2fbf -r 8cc3ca64a534 OrthancServer/ServerIndex.cpp --- a/OrthancServer/ServerIndex.cpp Thu Feb 08 11:51:41 2018 +0100 +++ b/OrthancServer/ServerIndex.cpp Mon Feb 19 16:55:05 2018 +0100 @@ -770,7 +770,7 @@ } // Attach the auto-computed metadata for the patient/study/series levels - std::string now = SystemToolbox::GetNowIsoString(); + std::string now = SystemToolbox::GetNowIsoString(true /* use UTC time (not local time) */); db_.SetMetadata(series, MetadataType_LastUpdate, now); db_.SetMetadata(study, MetadataType_LastUpdate, now); db_.SetMetadata(patient, MetadataType_LastUpdate, now); @@ -1281,7 +1281,7 @@ type, publicId, remoteModality, - SystemToolbox::GetNowIsoString(), + SystemToolbox::GetNowIsoString(true /* use UTC time (not local time) */), patientId, studyInstanceUid, seriesInstanceUid, diff -r 0c57f40e2fbf -r 8cc3ca64a534 OrthancServer/ServerIndexChange.h --- a/OrthancServer/ServerIndexChange.h Thu Feb 08 11:51:41 2018 +0100 +++ b/OrthancServer/ServerIndexChange.h Mon Feb 19 16:55:05 2018 +0100 @@ -59,7 +59,7 @@ changeType_(changeType), resourceType_(resourceType), publicId_(publicId), - date_(SystemToolbox::GetNowIsoString()) + date_(SystemToolbox::GetNowIsoString(true /* use UTC time (not local time) */)) { } diff -r 0c57f40e2fbf -r 8cc3ca64a534 UnitTestsSources/UnitTestsMain.cpp --- a/UnitTestsSources/UnitTestsMain.cpp Thu Feb 08 11:51:41 2018 +0100 +++ b/UnitTestsSources/UnitTestsMain.cpp Mon Feb 19 16:55:05 2018 +0100 @@ -908,6 +908,20 @@ } +TEST(Toolbox, Now) +{ + LOG(WARNING) << "Local time: " << SystemToolbox::GetNowIsoString(false); + LOG(WARNING) << "Universal time: " << SystemToolbox::GetNowIsoString(true); + + std::string date, time; + SystemToolbox::GetNowDicom(date, time, false); + LOG(WARNING) << "Local DICOM time: [" << date << "] [" << time << "]"; + + SystemToolbox::GetNowDicom(date, time, true); + LOG(WARNING) << "Universal DICOM time: [" << date << "] [" << time << "]"; +} + + #if ORTHANC_ENABLE_PUGIXML == 1 TEST(Toolbox, Xml)