/* Set the elapsed time based on the given instance and the pointer to the elapsed time option. */
VOID SetElapsedTime(IN UINT16 *Elapsed, IN DHCP6_INSTANCE *Instance)
/* Set the elapsed time based on the given instance and the pointer to the elapsed time option. */
VOID SetElapsedTime(IN UINT16 *Elapsed, IN DHCP6_INSTANCE *Instance)
{
  EFI_TIME  Time;
  UINT64    CurrentStamp;
  UINT64    ElapsedTimeValue;
  gRT->GetTime (&Time, NULL);
  CurrentStamp = MultU64x32 (
                   ((((UINT32)(Time.Year - 2000) * 360 + (Time.Month - 1) * 30 + (Time.Day - 1)) * 24 + Time.Hour) * 60 + Time.Minute) * 60 + Time.Second,
                   100
                   ) +
                 DivU64x32 (
                   Time.Nanosecond,
                   10000000
                   );
  if (Instance->StartTime == 0) {
    ElapsedTimeValue    = 0;
    Instance->StartTime = CurrentStamp;
  } else {
    ElapsedTimeValue = CurrentStamp - Instance->StartTime;
    if (ElapsedTimeValue > 0xffff) {
      ElapsedTimeValue = 0xffff;
    }
  }
  WriteUnaligned16 (Elapsed, HTONS ((UINT16)ElapsedTimeValue));
}