Skip to content

Unexpected GMTOffset when field contains date only #558

@stormcrow79

Description

@stormcrow79

Describe the bug
When a TS field (such as PID-7 Date/Time of Birth) contains a date and time without an offset, TSComponentOne.GMTOffset contains the placeholder -99.

When a TS field contains a date only, without time or offset, TSComponentOne.GMTOffset contains the local offset instead of the expected placeholder -99.

To Reproduce

foreach (var value in new[] { "20230603", "202306031234", "20230603+0800", "202306031234+0800" })
{
  var message = new NHapi.Model.V24.Message.ADT_A05();
  message.PID.DateTimeOfBirth.TimeOfAnEvent.Value = value;

  Console.WriteLine(message.PID.DateTimeOfBirth.TimeOfAnEvent.GMTOffset);
}

// expected -99, -99, 800, 800
// actual 800, -99, 800, 800

Expected behaviour
When a TS field contains a date only, without time or offset, TSComponentOne.GMTOffset contains the placeholder -99.

Environmental Details (please complete the following information):

  • OS: Windows 10
  • Target Framework: netstandard2.0
  • Version: 3.1.1
  • HL7 Version: 2.3.1 and 2.4

Additional context
This appears to be specific behavior in the setter for CommonTS.Value as shown below, which seems really strange. I'd expect the offset to be ignored for a date-only value, since it's only meaningful in the presence of a time.

// if the offset does not exist and a time value does not exist then
// we must provide a default offset = to the local time zone
if (timeVal == null && offsetExists == false)
{
  var defaultOffset = DataTypeUtil.LocalGMTOffset;
  tm = new CommonTM();
  tm.Offset = defaultOffset;
} // end if

// if we have a time value then make a new time object and set it to the
// input time value (as long as the time val has time + offset or just time only)
if (timeVal != null && timeValIsOffsetOnly == false)
{
  // must make sure that the time component contains both hours and minutes
  // at the very least -- must be at least 4chars in length.
  if (timeValLessOffset.Length < 4) { ... }}

  tm = new CommonTM();
  tm.Value = timeVal;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions