Skip to content

Commit 121e28a

Browse files
committed
Output operator now prints optional information.
The output operator of OFDateTime and OFTime now also prints optional information such as seconds, fraction of seconds and time zone (if available).
1 parent 67ad605 commit 121e28a

6 files changed

Lines changed: 24 additions & 21 deletions

File tree

dcmdata/tests/tvrdatim.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ OFTEST(dcmdata_dateTime)
137137
OFCHECK(DcmTime::getTimeZoneFromString("+100", timeZone).bad());
138138
OFCHECK(DcmTime::getTimeZoneFromString("UTC+1", timeZone).bad());
139139

140-
dcmDateTime.putString("200204101203+0500");
140+
dcmDateTime.putString("20020410120315+0500");
141141
dcmDateTime.print(strstream);
142-
CHECK_EQUAL("(0040,a120) DT [200204101203+0500] # 18, 1 DateTime\n");
142+
CHECK_EQUAL("(0040,a120) DT [20020410120315+0500] # 20, 1 DateTime\n");
143143
OFCHECK(dcmDateTime.getOFDateTime(dateTime).good());
144-
CHECK_STREAM_EQUAL(dateTime, "2002-04-10 12:03");
144+
CHECK_STREAM_EQUAL(dateTime, "2002-04-10 12:03:15 +05:00");
145145

146146
dcmDateTime.putString("20020410");
147147
dcmDateTime.print(strstream);

ofstd/include/dcmtk/ofstd/ofdatime.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ class DCMTK_OFSTD_EXPORT OFDateTime
252252
* if OFTrue. The time zone indicates the offset from the Coordinated Universal Time (UTC)
253253
* in hours and minutes. The time zone is only added if a value is specified.
254254
* @param showDelimiter flag, indicating whether to use delimiters ("-", ":" and " ") or not
255-
* @param createMissingPart if OFTrue create optional parts (seconds and fractional part of a
255+
* @param createMissingPart if OFTrue, create optional parts (seconds and fractional part of a
256256
* second) even if not specified (see OFTime::hasSecond() and OFTime::hasFractionOfSecond())
257257
* @param dateTimeSeparator separator between ISO date and time value, e.g. " " (default) or
258258
* "T" (for ISO 8601 format). Only used if 'showDelimiter' is true.
@@ -293,7 +293,8 @@ class DCMTK_OFSTD_EXPORT OFDateTime
293293

294294

295295
/** put the given date/time in ISO format on the output stream.
296-
* If an error occurs nothing is printed.
296+
* The output format is "YYYY-MM-DD HH:MM[:SS[.FFFFFF]] [&ZZ:ZZ]". Optional parts are not
297+
* created if missing. If an error occurs nothing is printed.
297298
* @param stream output stream
298299
* @param time OFDateTime object to print
299300
* @return reference to the output stream

ofstd/include/dcmtk/ofstd/oftime.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@ class DCMTK_OFSTD_EXPORT OFTime
145145
*/
146146
virtual void clear();
147147

148-
/** clear the second value, i.e.\ set it to "unspecified".
148+
/** clear the second value, i.e.\ set it to "unspecified"
149149
*/
150150
void clearSecond();
151151

152-
/** clear the time zone value, i.e.\ set it to "unspecified".
152+
/** clear the time zone value, i.e.\ set it to "unspecified"
153153
*/
154154
void clearTimeZone();
155155

@@ -241,7 +241,7 @@ class DCMTK_OFSTD_EXPORT OFTime
241241
/** set the time to the specified number of seconds
242242
* @param seconds number of seconds since "00:00:00" specifying time to set
243243
* @param timeZone optional offset to Coordinated Universal Time (UTC) in hours
244-
* @param normalize if OFTrue the 'seconds' value is normalized to the valid range
244+
* @param normalize if OFTrue, the 'seconds' value is normalized to the valid range
245245
* [0.0,86400.0[ otherwise the value is checked as is
246246
* @return OFTrue if the new value is valid and has been set, OFFalse otherwise
247247
*/
@@ -252,7 +252,7 @@ class DCMTK_OFSTD_EXPORT OFTime
252252
/** set the time to the specified number of hours
253253
* @param hours number of hours since "00:00:00" specifying time to set
254254
* @param timeZone optional offset to Coordinated Universal Time (UTC) in hours
255-
* @param normalize if OFTrue the 'hours' value is normalized to the valid range
255+
* @param normalize if OFTrue, the 'hours' value is normalized to the valid range
256256
* [0.0,24.0[ otherwise the value is checked as is
257257
* @return OFTrue if the new value is valid and has been set, OFFalse otherwise
258258
*/
@@ -339,7 +339,7 @@ class DCMTK_OFSTD_EXPORT OFTime
339339

340340
/** get the currently stored time in seconds
341341
* @param useTimeZone use the currently set time zone to correct the result
342-
* @param normalize if OFTrue results larger than or equal 86400.0 (seconds)
342+
* @param normalize if OFTrue, results larger than or equal 86400.0 (seconds)
343343
* are normalized to a valid range
344344
* @return number of seconds since "00:00:00"
345345
*/
@@ -348,7 +348,7 @@ class DCMTK_OFSTD_EXPORT OFTime
348348

349349
/** get the currently stored time in hours.
350350
* @param useTimeZone use the currently set time zone to correct the result
351-
* @param normalize if OFTrue results larger than or equal 24.0 (hours) are
351+
* @param normalize if OFTrue, results larger than or equal 24.0 (hours) are
352352
* normalized to a valid range
353353
* @return number of hours since "00:00:00" (including fraction of hours)
354354
*/
@@ -388,8 +388,8 @@ class DCMTK_OFSTD_EXPORT OFTime
388388
* if OFTrue. The time zone indicates the offset from the Coordinated Universal Time (UTC)
389389
* in hours and minutes. The time zone is only added if a value is specified.
390390
* @param showDelimiter flag, indicating whether to use delimiters (":" and " ") or not
391-
* @param createMissingPart if OFTrue create optional parts (seconds and fractional part of a
392-
* second) even if not specified (see hasSecond() and hasFractionOfSecond())
391+
* @param createMissingPart if OFTrue, create optional parts (seconds and fractional part of
392+
* a second) even if not specified (see hasSecond() and hasFractionOfSecond())
393393
* @param timeZoneSeparator separator between ISO time value and time zone, e.g. " " (default)
394394
* or "" (for ISO 8601 format). Only used if 'showDelimiter' is true.
395395
* @return OFTrue if result variable has been set, i.e. the time is valid, OFFalse otherwise
@@ -487,7 +487,7 @@ class DCMTK_OFSTD_EXPORT OFTime
487487
* @param minute minute value of the given time
488488
* @param second second value of the given time
489489
* @param timeZone optional offset to Coordinated Universal Time (UTC) in hours
490-
* @param normalize if OFTrue results larger than or equal 86400.0 (seconds)
490+
* @param normalize if OFTrue, results larger than or equal 86400.0 (seconds)
491491
* are normalized to a valid range
492492
* @return number of seconds since "00:00:00"
493493
*/
@@ -502,7 +502,7 @@ class DCMTK_OFSTD_EXPORT OFTime
502502
* @param minute minute value of the given time
503503
* @param second second value of the given time
504504
* @param timeZone optional offset to Coordinated Universal Time (UTC) in hours
505-
* @param normalize if OFTrue results larger than or equal 24.0 (hours)
505+
* @param normalize if OFTrue, results larger than or equal 24.0 (hours)
506506
* are normalized to a valid range
507507
* @return number of hours since "00:00:00" (including fraction of hours)
508508
*/
@@ -530,7 +530,8 @@ class DCMTK_OFSTD_EXPORT OFTime
530530

531531

532532
/** put the given time in ISO format on the output stream.
533-
* If an error occurs, nothing is printed.
533+
* The output format is "HH:MM[:SS[.FFFFFF]] [&ZZ:ZZ]". Optional parts are not created
534+
* if missing. If an error occurs nothing is printed.
534535
* @param stream output stream
535536
* @param timeVal OFTime object to print
536537
* @return reference to the output stream

ofstd/libsrc/ofdatime.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ STD_NAMESPACE ostream &operator<<(STD_NAMESPACE ostream &stream,
330330
{
331331
OFString string;
332332
/* print the given date and time in ISO format to the stream */
333-
if (dateTime.getISOFormattedDateTime(string))
333+
if (dateTime.getISOFormattedDateTime(string, OFTrue /*showSeconds*/, OFTrue /*showFraction*/, OFTrue /*showTimeZone*/))
334334
stream << string;
335335
return stream;
336336
}

ofstd/libsrc/oftime.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -750,11 +750,11 @@ OFBool OFTime::getISOFormattedTime(OFString &formattedTime,
750750
/* format: HHMM */
751751
else
752752
OFStandard::snprintf(buf, sizeof(buf), "%02u%02u", Hour, Minute);
753-
/* only show seconds if requested and a value is specified (or a value is created) */
753+
/* only show seconds if requested and a value is specified (or should be created) */
754754
if (showSeconds && (hasSecond() || createMissingPart))
755755
{
756756
const double secondValue = isSecondSpecified(Second) ? Second : 0;
757-
/* only show fractional part of a second if requested and a value is specified (or a value is created) */
757+
/* only show fractional part of a second if requested and a value is specified (or should be created) */
758758
if (showFraction && (hasFractionOfSecond() || createMissingPart))
759759
{
760760
char buf2[12];
@@ -902,7 +902,7 @@ STD_NAMESPACE ostream &operator<<(STD_NAMESPACE ostream &stream,
902902
{
903903
OFString tmpString;
904904
/* print the given time in ISO format to the stream */
905-
if (timeVal.getISOFormattedTime(tmpString))
905+
if (timeVal.getISOFormattedTime(tmpString, OFTrue /*showSeconds*/, OFTrue /*showFraction*/, OFTrue /*showTimeZone*/))
906906
stream << tmpString;
907907
return stream;
908908
}

ofstd/tests/tofdatim.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ OFTEST(ofstd_OFDateTime)
309309
COUT << "current date/time (default): " << dateTime1 << OFendl;
310310
dateTime1.getISOFormattedDateTime(tmpString, OFTrue /*showSeconds*/, OFFalse /*showFraction*/, OFTrue /*showTimeZone*/);
311311
COUT << "current date/time (YYYY-MM-DD HH:MM:SS&ZZ:ZZ): " << tmpString << OFendl;
312-
dateTime1.getISOFormattedDateTime(tmpString, OFTrue /*showSeconds*/, OFTrue /*showFraction*/, OFTrue /*showTimeZone*/, OFFalse /*showDelimiter*/, OFFalse /*showDelimiter*/, "" /*dateTimeSeparator*/);
312+
dateTime1.getISOFormattedDateTime(tmpString, OFTrue /*showSeconds*/, OFTrue /*showFraction*/, OFTrue /*showTimeZone*/,
313+
OFFalse /*showDelimiter*/, OFTrue /*createMissingPart*/, /*showDelimiter*/, "" /*dateTimeSeparator*/);
313314
COUT << "current date/time (YYYYMMDDHHMMSS.FFFFFF&ZZZZ): " << tmpString << OFendl;
314315
#endif

0 commit comments

Comments
 (0)