예제 #1
0
 /// <summary>
 /// Returns the Precision found in the Hl7 DateTime string passed in.
 /// If the string passed in cannot be parsed as a HL7 dateTime string then a FormatException is thrown.
 /// </summary>
 /// <param name="Hl7DateTimeString"></param>
 /// <returns></returns>
 public static DateTimePrecision GetPrecision(string Hl7DateTimeString)
 {
     if (DateTimeSupportTools.CanParseToDateTimeOffset(Hl7DateTimeString))
     {
         return(CalculateDateTimePrecision(Hl7DateTimeString));
     }
     else
     {
         return(DateTimePrecision.None);
     }
 }
예제 #2
0
 /// <summary>
 /// Returns True if a Time-zone element is found in the Hl7 DateTime string.
 /// If the string passed in cannot be parsed as a dateTime then a FormatException is thrown.
 /// </summary>
 /// <param name="Hl7DateTimeString"></param>
 /// <returns></returns>
 public static bool HasTimezone(string Hl7DateTimeString)
 {
     if (DateTimeSupportTools.CanParseToDateTimeOffset(Hl7DateTimeString))
     {
         return(CheckForTimezone(Hl7DateTimeString));
     }
     else
     {
         throw new PeterPiperArgumentException(String.Format(FormatExceptionMessage, Hl7DateTimeString));
     }
 }
예제 #3
0
 /// <summary>
 /// Set the time-zone for a give HL7 DateTime string. This will convert the date time from the time-zone present to the new time zone.
 /// If no time-zone is present in the HL7 date time string then it will assume that this date time is from the new time zone and not convert.
 /// Will throw a FormatException if the HL7 DateTime string is no able to be parsed as a DateTimeOffset.
 /// </summary>
 /// <param name="Hl7DateTimeString"></param>
 /// <param name="Timespan"></param>
 /// <returns></returns>
 public static string SetTimezone(string Hl7DateTimeString, TimeSpan Timespan)
 {
     if (DateTimeSupportTools.HasTimezone(Hl7DateTimeString))
     {
         var DateTime = DateTimeSupportTools.AsDateTimeOffSet(Hl7DateTimeString);
         DateTime = DateTime.ToOffset(Timespan);
         return(DateTimeSupportTools.AsString(DateTime, true, DateTimeSupportTools.GetPrecision(Hl7DateTimeString)));
     }
     else
     {
         return(Hl7DateTimeString + String.Format("{0:+00;-00}{1:00}", Timespan.Hours, Timespan.Minutes));
     }
 }
예제 #4
0
 /// <summary>
 /// Returns a Timespan that represents the time zone found in the HL7 DateTime string.
 /// Throws a FormatException if no time zone present or if the content is empty
 /// </summary>
 /// <param name="Hl7DateTimeString"></param>
 /// <returns></returns>
 public static TimeSpan GetTimezone(string Hl7DateTimeString)
 {
     if (DateTimeSupportTools.HasTimezone(Hl7DateTimeString))
     {
         char[] TimeZomeDelimiter = { '+', '-' };
         try
         {
             var TimeZoneString = Hl7DateTimeString.Substring(Hl7DateTimeString.LastIndexOfAny(TimeZomeDelimiter), Hl7DateTimeString.Length - Hl7DateTimeString.LastIndexOfAny(TimeZomeDelimiter));
             int Hours          = System.Convert.ToInt32(TimeZoneString.Substring(0, 3));
             int min            = System.Convert.ToInt32(TimeZoneString.Substring(3, 2));
             return(new TimeSpan(Hours, min, 0));
         }
         catch (Exception Exec)
         {
             throw new PeterPiperArgumentException(String.Format("Unable to parse time-zone from HL7 date time string of: {0}", Hl7DateTimeString), Exec);
         }
     }
     else
     {
         throw new PeterPiperArgumentException(String.Format("No time-zone present in given content. Try testing for time-zone by calling 'HasTimezone' before calling 'GetTimezone'."));
     }
 }