public void DurationTest() { var durSpan = new TimeSpan(25, 15, 56, 12); var duration = new IfcDuration("P25DT15H56M12.000S"); TimeSpan span = duration; IfcDuration spanDur = span; Assert.AreEqual(durSpan, span); Assert.AreEqual(duration, spanDur); //test negative durSpan = new TimeSpan(-25, -15, -56, -12); duration = new IfcDuration("-P25DT15H56M12.000S"); span = duration; spanDur = span; Assert.AreEqual(durSpan, span); Assert.AreEqual(duration, spanDur); }
public void DateTimeTest() { var dt = new DateTime(2016, 3, 31, 10, 54, 2); IfcDate date = dt; Assert.AreEqual(date.ToString(), "2016-03-31"); Assert.AreEqual((DateTime)date, new DateTime(2016, 3, 31)); date = "2016-03-31"; Assert.AreEqual((DateTime)date, new DateTime(2016, 3, 31)); IfcDateTime dateTime = dt; Assert.AreEqual(dateTime.ToString(), "2016-03-31T10:54:02.0000000"); dateTime = "2016-03-31T10:54:02"; Assert.AreEqual((DateTime)dateTime, dt); IfcTimeStamp stamp = dt; Assert.AreEqual((TimeSpan)stamp, dt - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)); IfcTime time = dt; Assert.AreEqual(time.ToString(), "10:54:02.0000000"); time = "10:54:02.0000000"; var sTime = DateTime.Today.AddHours(10).AddMinutes(54).AddSeconds(2); Assert.AreEqual((DateTime)time, sTime); var span = new TimeSpan(9, 5, 32, 45, 12); IfcDuration duration = span; Assert.AreEqual(duration.ToString(), "P9DT5H32M45.012S"); Assert.AreEqual(span, (TimeSpan)duration); }
internal double getSecondsDuration() { IfcDuration d = mLagValue as IfcDuration; return(d == null ? 0 : d.ToSeconds()); }
internal static IfcSimpleValue parseSimpleValue(string str) { if (str.StartsWith("IFCBOOLEAN(")) { return(new IfcBoolean(string.Compare(str.Substring(11, str.Length - 12), ".T.") == 0)); } if (str.StartsWith("IFCIDENTIFIER(")) { return(new IfcIdentifier(ParserIfc.Decode(str.Substring(15, str.Length - 17)))); } if (str.StartsWith("IFCINTEGER(")) { return(new IfcInteger(long.Parse(str.Substring(11, str.Length - 12)))); } if (str.StartsWith("IFCLABEL(")) { if (str.Length <= 12) { return(new IfcLabel("")); } string s = str.Substring(10, str.Length - 12); return(new IfcLabel((str[10] == '$' || s == null ? "" : ParserIfc.Decode(s)))); } if (str.StartsWith("IFCLOGICAL(")) { string s = str.Substring(11, str.Length - 12); IfcLogicalEnum l = IfcLogicalEnum.UNKNOWN; if (s == ".T.") { l = IfcLogicalEnum.TRUE; } else if (s == ".F.") { l = IfcLogicalEnum.FALSE; } return(new IfcLogical(l)); } if (str.StartsWith("IFCREAL(")) { return(new IfcReal(ParserSTEP.ParseDouble(str.Substring(8, str.Length - 9)))); } if (str.StartsWith("IFCTEXT(")) { string s = str.Substring(9, str.Length - 11); return(new IfcText((str[9] == '$' || s == null ? "" : ParserIfc.Decode(s)))); } if (str.StartsWith("IFCURIREFERENCE(")) { return(new IfcURIReference(str[16] == '$' ? "" : ParserIfc.Decode(str.Substring(17, str.Length - 19)))); } if (str.StartsWith("IFCDURATION(")) { return(IfcDuration.Convert(str.Substring(13, str.Length - 15))); } int i = 0; if (int.TryParse(str, out i)) { return(new IfcInteger(i)); } double d = 0; if (double.TryParse(str, System.Globalization.NumberStyles.Any, ParserSTEP.NumberFormat, out d)) { return(new IfcReal(d)); } if (str == ".T.") { return(new IfcBoolean(true)); } if (str == ".F.") { return(new IfcBoolean(false)); } if (str == ".U.") { return(new IfcLogical(IfcLogicalEnum.UNKNOWN)); } return(null); }