private HDateTime(DateTimeOffset dto, HTimeZone htz) { m_dtoParsed = dto; TimeZone = htz; date = HDate.make(dto.Year, dto.Month, dto.Day); time = HTime.make(dto.Hour, dto.Minute, dto.Second, dto.Millisecond); }
// Parse from string fomat "hh:mm:ss.FF" or "hh:mm:ss" or raise FormatException (replaces ParseException) public static HTime make(string s) { string strToConv = s; DateTime dtParsed = DateTime.Now; string strFormat = ""; if (s.Contains(".")) { strFormat = "HH:mm:ss.fff"; // Unit tests show that the fff can't be more than 3 chars int iDotPos = strToConv.IndexOf("."); if ((strToConv.Length - iDotPos > 3) && (strToConv.Length > 12)) { strToConv = strToConv.Substring(0, 12); } else if ((strToConv.Length - iDotPos < 4) && (strToConv.Length < 12)) { // HH:mm:ss.ff int iAddZeros = 3 - (strToConv.Length - iDotPos - 1); for (int i = 0; i < iAddZeros; i++) { strToConv += '0'; } } } else { strFormat = "HH:mm:ss"; } // Unit tests show that the fff can't be more than 3 chars if (!DateTime.TryParseExact(strToConv, strFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out dtParsed)) { throw new FormatException("Invalid time string: " + s); } return(HTime.make(dtParsed.Hour, dtParsed.Minute, dtParsed.Second, dtParsed.Millisecond)); }
// Constructor with date and time (to sec) fields public static HDateTime make(int year, int month, int day, int hour, int min, int sec, HTimeZone tz) { return(make(HDate.make(year, month, day), HTime.make(hour, min, sec), tz)); }