/// <summary> Returns a string value representing the input Gregorian Calendar object in /// an Hl7 Date Format. /// </summary> public static String toHl7DTFormat(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); CommonDT dt = new CommonDT(); dt.setYearMonthDayPrecision(calYear, calMonth, calDay); val = dt.Value; } catch (DataTypeException e) { throw e; } catch (Exception e) { throw new DataTypeException("An unexpected exception ocurred", e); } return(val); }
} //end constructor /// <summary> This method takes in integer values for the year and month and day /// and performs validations, it then sets the value in the object /// formatted as an HL7 Time Stamp value with year and month and day precision (YYYYMMDD). /// /// </summary> public virtual void setDatePrecision(int yr, int mnth, int dy) { try { //create date object if there isn't one if (dt == null) { dt = new CommonDT(); } //set the value of the date object to the input date value dt.setYearMonthDayPrecision(yr, mnth, dy); //clear the time value object tm = null; } //end try catch (DataTypeException e) { throw e; } //end catch catch (System.Exception e) { throw new DataTypeException("An unexpected exception ocurred", e); } //end catch }
public void setYearMonthDayPrecision_With_Invalid_Day() { var commonDt = new CommonDT(); commonDt.setYearMonthDayPrecision(2001, 2, 29); }
public void setYearMonthDayPrecision_With_Valid_Year_and_Month_and_Day() { var commonDt = new CommonDT(); commonDt.setYearMonthDayPrecision(2001, 2, 3); Assert.AreEqual("20010203", commonDt.Value); Assert.AreEqual(2001, commonDt.Year); Assert.AreEqual(2, commonDt.Month); Assert.AreEqual(3, commonDt.Day); }
/// <summary> Returns a string value representing the input Gregorian Calendar object in /// an Hl7 Date Format. /// </summary> public static System.String toHl7DTFormat(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); CommonDT dt = new CommonDT(); dt.setYearMonthDayPrecision(calYear, calMonth, calDay); val = dt.Value; } catch (DataTypeException e) { throw e; } catch (System.Exception e) { throw new DataTypeException("An unexpected exception ocurred", e); } return val; }