/// <summary> /// Comparison on this and the supplied dates and times (taking timezones /// into account) /// </summary> /// <param name="arg"> /// XSDateTime representation of the date to compare to </param> /// <exception cref="DynamicError"> </exception> /// <returns> True if in time, this date and time lies after the date and time /// supplied. False otherwise. </returns> public virtual bool gt(AnyType arg, DynamicContext context) { XSDateTime val = (XSDateTime)NumericType.get_single_type(arg, typeof(XSDateTime)); Calendar thiscal = normalizeCalendar(calendar(), tz()); Calendar thatcal = normalizeCalendar(val.calendar(), val.tz()); return(thiscal.CompareTo(thatcal) > 0); }
private ResultSequence minusXSDateTime(ResultSequence arg) { XSDateTime val = (XSDateTime)NumericType.get_single_type(arg, typeof(XSDateTime)); Calendar thisCal = normalizeCalendar(calendar(), tz()); Calendar thatCal = normalizeCalendar(val.calendar(), val.tz()); long duration = thisCal.getTimeInMillis() - thatCal.getTimeInMillis(); Duration dtduration = _datatypeFactory.newDuration(duration); return(ResultSequenceFactory.create_new(XSDayTimeDuration.parseDTDuration(dtduration.ToString()))); }
/// <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())); }
private CalendarType castTime(AnyAtomicType aat) { if (aat is XSTime) { XSTime time = (XSTime)aat; return(new XSTime(time.calendar(), time.tz())); } if (aat is XSDateTime) { XSDateTime dateTime = (XSDateTime)aat; return(new XSTime(dateTime.calendar(), dateTime.tz())); } return(parse_time(aat.StringValue)); }
private XSDate castDate(Item aat) { if (aat is XSDate) { XSDate date = (XSDate)aat; return(new XSDate(date.calendar(), date.tz())); } if (aat is XSDateTime) { XSDateTime dateTime = (XSDateTime)aat; return(new XSDate(dateTime.calendar(), dateTime.tz())); } return(parse_date(aat.StringValue)); }
private ResultSequence minusXSYearMonthDuration(Item at) { XSYearMonthDuration val = (XSYearMonthDuration)at; try { XSDateTime res = (XSDateTime)clone(); res.calendar().add(Calendar.MONTH, val.monthValue() * -1); return(ResultSequenceFactory.create_new(res)); } catch { } return(null); }
/// <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> /// Mathematical addition operator between this XSDateTime and a supplied /// result sequence (XDTYearMonthDuration and XDTDayTimeDuration are only /// valid ones). /// </summary> /// <param name="arg"> /// The supplied ResultSequence that is on the right of the minus /// operator. If arg is an XDTYearMonthDuration or an /// XDTDayTimeDuration the result will be a XSDateTime of the /// result of the current date minus the duration of time /// supplied. </param> /// <returns> New ResultSequence consisting of the result of the mathematical /// minus operation. </returns> public virtual ResultSequence plus(ResultSequence arg) { if (arg.size() != 1) { DynamicError.throw_type_error(); } Item at = arg.first(); try { if (at is XSYearMonthDuration) { XSYearMonthDuration val = (XSYearMonthDuration)at; XSDateTime res = (XSDateTime)clone(); res.calendar().add(Calendar.MONTH, val.monthValue()); return(ResultSequenceFactory.create_new(res)); } else if (at is XSDayTimeDuration) { XSDuration val = (XSDuration)at; XSDateTime res = (XSDateTime)clone(); XMLGregorianCalendar xmlCal = _datatypeFactory.newXMLGregorianCalendar((GregorianCalendar)calendar()); Duration dtduration = _datatypeFactory.newDuration(val.StringValue); xmlCal.add(dtduration); res = new XSDateTime(xmlCal.toGregorianCalendar(), res.tz()); return(ResultSequenceFactory.create_new(res)); } else { DynamicError.throw_type_error(); return(null); // unreach } } catch { Debug.Assert(false); return(null); } }
private XSGDay castGDay(AnyAtomicType aat) { if (aat is XSGDay) { XSGDay gday = (XSGDay)aat; return(new XSGDay(gday.calendar(), gday.tz())); } if (aat is XSDate) { XSDate date = (XSDate)aat; return(new XSGDay(date.calendar(), date.tz())); } if (aat is XSDateTime) { XSDateTime dateTime = (XSDateTime)aat; return(new XSGDay(dateTime.calendar(), dateTime.tz())); } return(parse_gDay(aat.StringValue)); }
/// <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())); }
private XSGYear castGYear(AnyAtomicType aat) { if (aat is XSGYear) { XSGYear gy = (XSGYear)aat; return(new XSGYear(gy.calendar(), gy.tz())); } if (aat is XSDate) { XSDate date = (XSDate)aat; return(new XSGYear(date.calendar(), date.tz())); } if (aat is XSDateTime) { XSDateTime dateTime = (XSDateTime)aat; return(new XSGYear(dateTime.calendar(), dateTime.tz())); } return(parse_gYear(aat.StringValue)); }
private XSGYearMonth castGYearMonth(AnyAtomicType aat) { if (aat is XSGYearMonth) { XSGYearMonth gym = (XSGYearMonth)aat; return(new XSGYearMonth(gym.calendar(), gym.tz())); } if (aat is XSDate) { XSDate date = (XSDate)aat; return(new XSGYearMonth(date.calendar(), date.tz())); } if (aat is XSDateTime) { XSDateTime dateTime = (XSDateTime)aat; return(new XSGYearMonth(dateTime.calendar(), dateTime.tz())); } return(parse_gYearMonth(aat.StringValue)); }
private XSGMonthDay castGMonthDay(AnyAtomicType aat) { if (aat is XSGMonthDay) { XSGMonthDay gmd = (XSGMonthDay)aat; return(new XSGMonthDay(gmd.calendar(), gmd.tz())); } if (aat is XSDate) { XSDate date = (XSDate)aat; return(new XSGMonthDay(date.calendar(), date.tz())); } if (aat is XSDateTime) { XSDateTime dateTime = (XSDateTime)aat; return(new XSGMonthDay(dateTime.calendar(), dateTime.tz())); } return(parse_gMonthDay(aat.StringValue)); }
/// <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())); }
private ResultSequence minusXSDayTimeDuration(Item at) { XSDuration val = (XSDuration)at; try { XSDateTime res = (XSDateTime)clone(); XMLGregorianCalendar xmlCal = _datatypeFactory.newXMLGregorianCalendar((GregorianCalendar)calendar()); Duration dtduration = _datatypeFactory.newDuration(val.StringValue); xmlCal.add(dtduration.negate()); res = new XSDateTime(xmlCal.toGregorianCalendar(), res.tz()); return(ResultSequenceFactory.create_new(res)); } catch { throw; } //catch (CloneNotSupportedException) //{ //} //return null; }
/// <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())); }