nHapiNET / nHapi

nHapi is the .Net port of the original Java project HAPI.
Mozilla Public License 2.0
277 stars 157 forks source link

Unexpected GMTOffset when field contains date only #558

Open stormcrow79 opened 7 months ago

stormcrow79 commented 7 months ago

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):

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;
}
milkshakeuk commented 6 months ago

@stormcrow79 I will look at this when I get the chance.