////////////////////////////////////////////////////////////////////////// // Parse ////////////////////////////////////////////////////////////////////////// internal DateTime parseDateTime(string s, TimeZone defTz, bool check) { try { // parse into fields tzOffset = System.Int32.MaxValue; parse(s); // now figure out what timezone to use TimeZone.Rule defRule = defTz.rule(year); if (tzName != null) { // use defTz if tzName was specified and matches any variations of defTz if (tzName == defTz.name() || tzName == defRule.stdAbbr || tzName == defRule.dstAbbr) { tz = defTz; } // try to map tzName to TimeZone, use defTz as fallback else { tz = TimeZone.fromStr(tzName, false); if (tz == null) tz = defTz; } } // if tzOffset was specified... else if (tzOffset != System.Int32.MaxValue) { // figure out what expected offset was for defTz int time = hour*3600 + min*60 + sec; int defOffset = defRule.offset + TimeZone.dstOffset(defRule, year, (int)mon.ordinal(), day, time); // if specified offset matches expected offset for defTz then // use defTz, otherwise use a vanilla GMT+/- timezone if (tzOffset == defOffset) tz = defTz; else tz = TimeZone.fromGmtOffset(tzOffset); } // no tzName or tzOffset specified, use defTz else tz = defTz; // construct DateTime return new DateTime(year, (int)mon.ordinal(), day, hour, min, sec, ns, tzOffset, tz); } catch (Exception) {} if (check) throw ParseErr.make("DateTime", s).val; return null; }
////////////////////////////////////////////////////////////////////////// // Parse ////////////////////////////////////////////////////////////////////////// internal DateTime parseDateTime(string s, TimeZone defTz, bool check) { try { // parse into fields tzOffset = System.Int32.MaxValue; parse(s); // now figure out what timezone to use TimeZone.Rule defRule = defTz.rule(year); if (tzName != null) { // use defTz if tzName was specified and matches any variations of defTz if (tzName == defTz.name() || tzName == defRule.stdAbbr || tzName == defRule.dstAbbr) { tz = defTz; } // try to map tzName to TimeZone, use defTz as fallback else { tz = TimeZone.fromStr(tzName, false); if (tz == null) { tz = defTz; } } } // if tzOffset was specified... else if (tzOffset != System.Int32.MaxValue) { // figure out what expected offset was for defTz int time = hour * 3600 + min * 60 + sec; int defOffset = defRule.offset + TimeZone.dstOffset(defRule, year, (int)mon.ordinal(), day, time); // if specified offset matches expected offset for defTz then // use defTz, otherwise use a vanilla GMT+/- timezone if (tzOffset == defOffset) { tz = defTz; } else { tz = TimeZone.fromGmtOffset(tzOffset); } } // no tzName or tzOffset specified, use defTz else { tz = defTz; } // construct DateTime return(new DateTime(year, (int)mon.ordinal(), day, hour, min, sec, ns, tzOffset, tz)); } catch (Exception) {} if (check) { throw ParseErr.make("DateTime", s).val; } return(null); }