예제 #1
0
        /// <summary> Returns a string value representing the input Gregorian Calendar object in
        /// an Hl7 TimeStamp Format.
        /// </summary>
        public static String toHl7TSFormat(GregorianCalendar cal)
        {
            String val = "";

            try
            {
                //set the input cal object so that it can report errors
                //on it's value
                int calYear  = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.YEAR);
                int calMonth = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.MONTH) + 1;
                int calDay   = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.DAY_OF_MONTH);
                int calHour  = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.HOUR_OF_DAY);
                int calMin   = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.MINUTE);
                int calSec   = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.SECOND);
                int calMilli = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.MILLISECOND);
                //the inputs seconds and milli seconds should be combined into a float type
                float fractSec    = calMilli / 1000F;
                float calSecFloat = calSec + fractSec;
                int   calOffset   = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.ZONE_OFFSET);
                //Note the input's Offset value is in milliseconds, we must convert it to
                //a 4 digit integer in the HL7 Offset format.
                int offSetSignInt;
                if (calOffset < 0)
                {
                    offSetSignInt = -1;
                }
                else
                {
                    offSetSignInt = 1;
                }
                //get the absolute value of the gmtOffSet
                int absGmtOffSet   = Math.Abs(calOffset);
                int gmtOffSetHours = absGmtOffSet / (3600 * 1000);
                int gmtOffSetMin   = (absGmtOffSet / 60000) % (60);
                //reset calOffset
                calOffset = ((gmtOffSetHours * 100) + gmtOffSetMin) * offSetSignInt;
                //Create an object of the TS class and populate it with the above values
                //then return the HL7 string value from the object
                CommonTS ts = new CommonTS();
                ts.setDateSecondPrecision(calYear, calMonth, calDay, calHour, calMin, calSecFloat);
                ts.Offset = calOffset;
                val       = ts.Value;
            }
            // end try
            catch (DataTypeException e)
            {
                throw e;
            }
            //end catch
            catch (Exception e)
            {
                throw new DataTypeException("An unexpected exception ocurred", e);
            }             //end catch
            return(val);
        }
예제 #2
0
파일: CommonTS.cs 프로젝트: snosrap/nhapi
 /// <summary> Returns a string value representing the input Gregorian Calendar object in
 /// an Hl7 TimeStamp Format.
 /// </summary>
 public static System.String toHl7TSFormat(System.Globalization.GregorianCalendar cal)
 {
     System.String val = "";
     try
     {
         //set the input cal object so that it can report errors
         //on it's value
         int calYear = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.YEAR);
         int calMonth = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.MONTH) + 1;
         int calDay = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.DAY_OF_MONTH);
         int calHour = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.HOUR_OF_DAY);
         int calMin = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.MINUTE);
         int calSec = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.SECOND);
         int calMilli = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.MILLISECOND);
         //the inputs seconds and milli seconds should be combined into a float type
         float fractSec = calMilli / 1000F;
         float calSecFloat = calSec + fractSec;
         int calOffset = SupportClass.CalendarManager.manager.Get(cal, SupportClass.CalendarManager.ZONE_OFFSET);
         //Note the input's Offset value is in milliseconds, we must convert it to
         //a 4 digit integer in the HL7 Offset format.
         int offSetSignInt;
         if (calOffset < 0)
         {
             offSetSignInt = -1;
         }
         else
         {
             offSetSignInt = 1;
         }
         //get the absolute value of the gmtOffSet
         int absGmtOffSet = System.Math.Abs(calOffset);
         int gmtOffSetHours = absGmtOffSet / (3600 * 1000);
         int gmtOffSetMin = (absGmtOffSet / 60000) % (60);
         //reset calOffset
         calOffset = ((gmtOffSetHours * 100) + gmtOffSetMin) * offSetSignInt;
         //Create an object of the TS class and populate it with the above values
         //then return the HL7 string value from the object
         CommonTS ts = new CommonTS();
         ts.setDateSecondPrecision(calYear, calMonth, calDay, calHour, calMin, calSecFloat);
         ts.Offset = calOffset;
         val = ts.Value;
     }
     // end try
     catch (DataTypeException e)
     {
         throw e;
     }
     //end catch
     catch (System.Exception e)
     {
         throw new DataTypeException("An unexpected exception ocurred", e);
     } //end catch
     return val;
 }