/// <summary> /// Creates a new XSTime representing the String represented supplied time /// </summary> /// <param name="str"> /// String represented time and timezone to be stored </param> /// <returns> New XSTime representing the supplied time </returns> public static CalendarType parse_time(string str) { string startdate = "1983-11-29T"; XSDateTime dt = XSDateTime.parseDateTime(startdate + str); if (dt == null) { return(null); } return(new XSTime(dt.calendar(), dt.tz())); }
/// <summary> /// Parses a String representation of a date (of the form year-month-day or /// year-month-day+timezone) and constructs a new XSDate representation of /// it. /// </summary> /// <param name="str"> /// The String representation of the date (and optional timezone) </param> /// <returns> The XSDate representation of the supplied date </returns> public static XSDate parse_date(string str) { string date = ""; string time = "T00:00:00.0"; int index = str.IndexOf('+', 1); if (index == -1) { index = str.IndexOf('-', 1); if (index == -1) { return(null); } index = str.IndexOf('-', index + 1); if (index == -1) { return(null); } index = str.IndexOf('-', index + 1); } if (index == -1) { index = str.IndexOf('Z', 1); } if (index != -1) { date = str.Substring(0, index); // here we go date += time; date += str.Substring(index, str.Length - index); } else { date = str + time; } // sorry again =D XSDateTime dt = XSDateTime.parseDateTime(date); if (dt == null) { return(null); } return(new XSDate(dt.calendar(), dt.tz())); }
/// <summary> /// Parses a String representation of a year and month and constructs a new /// XSGYearMonth representation of it. /// </summary> /// <param name="str"> /// The String representation of the year and month (and optional /// timezone) </param> /// <returns> The XSGYearMonth representation of the supplied date </returns> public static XSGYearMonth parse_gYearMonth(string str) { string yearMonth = ""; string dayTime = "-01T00:00:00.0"; int index = str.IndexOf('+', 1); if (index == -1) { index = str.IndexOf('-', 1); if (index == -1) { return(null); } index = str.IndexOf('-', index + 1); } if (index == -1) { index = str.IndexOf('Z', 1); } if (index != -1) { yearMonth = str.Substring(0, index); yearMonth += dayTime; yearMonth += str.Substring(index, str.Length - index); } else { yearMonth = str + dayTime; } XSDateTime dt = XSDateTime.parseDateTime(yearMonth); if (dt == null) { return(null); } return(new XSGYearMonth(dt.calendar(), dt.tz())); }
/// <summary> /// Parses a String representation of a year and constructs a new XSGYear /// representation of it. /// </summary> /// <param name="str"> /// The String representation of the year (and optional timezone) </param> /// <returns> The XSGYear representation of the supplied date </returns> public static XSGYear parse_gYear(string str) { string year = ""; string monthDaytime = "-01-01T00:00:00.0"; int index = str.IndexOf('+', 1); if (index == -1) { index = str.IndexOf('-', 1); } if (index == -1) { index = str.IndexOf('Z', 1); } if (index != -1) { year = str.Substring(0, index); year += monthDaytime; year += str.Substring(index, str.Length - index); } else { year = str + monthDaytime; } XSDateTime dt = XSDateTime.parseDateTime(year); if (dt == null) { return(null); } return(new XSGYear(dt.calendar(), dt.tz())); }
/// <summary> /// Parses a String representation of a day and constructs a new XSGDay /// representation of it. /// </summary> /// <param name="str"> /// The String representation of the day (and optional timezone) </param> /// <returns> The XSGDay representation of the supplied date </returns> public static XSGDay parse_gDay(string str) { string startdate = "1972-12-"; string starttime = "T00:00:00"; int index = str.LastIndexOf('+', str.Length); if (index == -1) { index = str.LastIndexOf('-'); } if (index == -1) { index = str.LastIndexOf('Z', str.Length); } if (index != -1) { int zIndex = str.LastIndexOf('Z', str.Length); if (zIndex == -1) { if (index > 4) { zIndex = index; } } if (zIndex == -1) { zIndex = str.LastIndexOf('+'); } string[] split = str.Split("-", true); startdate += split[3].Replace("Z", ""); if (str.IndexOf('T') != -1) { if (split.Length > 4) { string[] timesplit = split[4].Split(":", true); if (timesplit.Length < 3) { starttime = "T"; StringBuilder buf = new StringBuilder(starttime); for (int cnt = 0; cnt < timesplit.Length; cnt++) { buf.Append(timesplit[cnt] + ":"); } buf.Append("00"); starttime = buf.ToString(); } else { starttime += timesplit[0] + ":" + timesplit[1] + ":" + timesplit[2]; } } } startdate = startdate.Trim(); startdate += starttime; if (zIndex != -1) { startdate += str.Substring(zIndex); } } else { startdate += str + starttime; } XSDateTime dt = XSDateTime.parseDateTime(startdate); if (dt == null) { return(null); } return(new XSGDay(dt.calendar(), dt.tz())); }