private void AssertDateParsing(SifFormatter formatter, String stringValue, Calendar value) { Console.WriteLine("Testing Date parse of '" + stringValue + "' using " + formatter.ToString()); //Calendar testValue = formatter.ToDate(stringValue); DateTime testValue = (DateTime)formatter.ToDate(stringValue); Assertion.AssertEquals("Date Value", value, testValue); Assertion.AssertEquals("String Value", stringValue, (String)formatter.ToDateString(testValue)); testValue = (DateTime)formatter.ToDate(null); Assertion.AssertNull("Date value should be null", testValue); }
public bool ReadRaw(XmlReader reader, SifVersion version, SifElement parent, SifFormatter formatter) { string name = reader.LocalName; if (name.Equals(fDateElement)) { String dateValue = ConsumeElementTextValue(reader, version); DateTime?date = formatter.ToDate(dateValue); if (date.HasValue) { DateTime tsValue = date.Value; SifDateTime dateTime = new SifDateTime(tsValue); parent.SetField(dateTime.CreateField(parent, fElementDef)); } } else if (name.Equals(fTimeElement)) { String timeValue = ConsumeElementTextValue(reader, version); DateTime?time = formatter.ToTime(timeValue); if (time.HasValue) { DateTime val = time.Value; // See if the Timestamp field already exists on the parent SimpleField timeStampField = parent.GetField(fElementDef); if (timeStampField == null) { // Doesn't exist, create it SifDateTime dateTime = new SifDateTime(val); parent.SetField(dateTime.CreateField(parent, fElementDef)); } else { // Exists, update the time portion of the date SifDateTime sdt = (SifDateTime)timeStampField.SifValue; if (sdt != null && sdt.Value.HasValue) { DateTime tsValue = sdt.Value.Value; tsValue = tsValue.Add(val.TimeOfDay); sdt = new SifDateTime(tsValue); // Overwrite the current value parent.SetField(sdt.CreateField(parent, fElementDef)); } } } } else { return(false); } return(true); }
public bool ReadRaw( XmlReader reader, SifVersion version, SifElement parent, SifFormatter formatter ) { string name = reader.LocalName; if ( name.Equals( fDateElement ) ) { String dateValue = ConsumeElementTextValue( reader, version ); DateTime? date = formatter.ToDate( dateValue ); if ( date.HasValue ) { DateTime tsValue = date.Value; SifDateTime dateTime = new SifDateTime( tsValue ); parent.SetField( dateTime.CreateField( parent, fElementDef ) ); } } else if ( name.Equals( fTimeElement ) ) { String timeValue = ConsumeElementTextValue( reader, version ); DateTime? time = formatter.ToTime( timeValue ); if ( time.HasValue ) { DateTime val = time.Value; // See if the Timestamp field already exists on the parent SimpleField timeStampField = parent.GetField( fElementDef ); if ( timeStampField == null ) { // Doesn't exist, create it SifDateTime dateTime = new SifDateTime( val ); parent.SetField( dateTime.CreateField( parent, fElementDef ) ); } else { // Exists, update the time portion of the date SifDateTime sdt = (SifDateTime) timeStampField.SifValue; if ( sdt != null && sdt.Value.HasValue ) { DateTime tsValue = sdt.Value.Value; tsValue = tsValue.Add( val.TimeOfDay ); sdt = new SifDateTime( tsValue ); // Overwrite the current value parent.SetField( sdt.CreateField( parent, fElementDef ) ); } } } } else { return false; } return true; }
private void assertThrowsFormatException(SifFormatter formatter) { bool threwProperException = false; // Boolean try { formatter.ToBool("asdf"); } catch (FormatException) { threwProperException = true; } Assertion.Assert("NumberFormatException was not thrown for toBoolean()", threwProperException); // DECIMAL threwProperException = false; try { formatter.ToDecimal("asdf"); } catch (FormatException) { threwProperException = true; } Assertion.Assert("IllegalArgumentException was not thrown for toDecimal()", threwProperException); // DATE threwProperException = false; try { formatter.ToDate("asdf"); } catch (FormatException) { threwProperException = true; } Assertion.Assert("IllegalArgumentException was not thrown for ToDate()", threwProperException); // // DateTime and Duration are not supported by the SIF1xFormatter // if (!(formatter is Sif1xFormatter)) { // DATETIME threwProperException = false; try { formatter.ToDateTime("asdf"); } catch (FormatException) { threwProperException = true; } Assertion.Assert("IllegalArgumentException was not thrown for ToDateTime()", threwProperException); // DURATION threwProperException = false; try { formatter.ToTimeSpan("asdf"); } catch (FormatException) { threwProperException = true; } Assertion.Assert("IllegalArgumentException was not thrown for toDuration()", threwProperException); } // INT threwProperException = false; try { formatter.ToInt("asdf"); } catch (FormatException) { threwProperException = true; } Assertion.Assert("IllegalArgumentException was not thrown for toint()", threwProperException); // TIME threwProperException = false; try { formatter.ToTime("asdf"); } catch (FormatException) { threwProperException = true; } Assertion.Assert("IllegalArgumentException was not thrown for toTime()", threwProperException); }