/// <summary> /// Evaluate the function using the arguments passed. /// </summary> /// <param name="args"> /// Result from the expressions evaluation. </param> /// <param name="sc"> /// Result of static context operation. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of the fn:dateTime operation. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence adjustDate(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.DynamicContext dc) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static ResultSequence adjustDate(ICollection args, DynamicContext dc) { ICollection cargs = Function.convert_arguments(args, expectedArgs()); // get args IEnumerator argiter = cargs.GetEnumerator(); argiter.MoveNext(); ResultSequence arg1 = (ResultSequence)argiter.Current; if (arg1 == null || arg1.empty()) { return(ResultBuffer.EMPTY); } ResultSequence arg2 = ResultBuffer.EMPTY; if (argiter.MoveNext()) { //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: arg2 = (ResultSequence)argiter.Current; } XSDate date = (XSDate)arg1.item(0); XSDayTimeDuration timezone = null; if (arg2.empty()) { if (date.timezoned()) { XSDate localized = new XSDate(date.calendar(), null); return(localized); } return(arg1); } timezone = (XSDayTimeDuration)arg2.item(0); if (timezone.lt(minDuration, dc) || timezone.gt(maxDuration, dc)) { throw DynamicError.invalidTimezone(); } if (date.tz() == null) { return(new XSDate(date.calendar(), timezone)); } XMLGregorianCalendar xmlCalendar = _datatypeFactory.newXMLGregorianCalendar((GregorianCalendar)date.normalizeCalendar(date.calendar(), date.tz())); Duration duration = _datatypeFactory.newDuration(timezone.StringValue); xmlCalendar.add(duration); return(new XSDate(xmlCalendar.toGregorianCalendar(), timezone)); }
/// <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 ResultSequence minusXSDayTimeDuration(AnyType at) { XSDuration val = (XSDuration)at; try { XSDate res = (XSDate)clone(); XMLGregorianCalendar xmlCal = _datatypeFactory .newXMLGregorianCalendar( (GregorianCalendar)calendar()); Duration dtduration = _datatypeFactory.newDuration(val.StringValue); xmlCal.add(dtduration.negate()); res = new XSDate(xmlCal.toGregorianCalendar(), res.tz()); return(ResultSequenceFactory.create_new(res)); } catch { } return(null); }
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> /// Evaluate the function using the arguments passed. /// </summary> /// <param name="args"> /// Result from the expressions evaluation. </param> /// <param name="sc"> /// Result of static context operation. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of the fn:dateTime operation. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence adjustTime(java.util.Collection args, org.eclipse.wst.xml.xpath2.api.DynamicContext dc) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static ResultSequence adjustTime(ICollection args, DynamicContext dc) { ICollection cargs = Function.convert_arguments(args, expectedArgs()); // get args IEnumerator argiter = cargs.GetEnumerator(); argiter.MoveNext(); ResultSequence arg1 = (ResultSequence)argiter.Current; if (arg1 == null || arg1.empty()) { return(ResultBuffer.EMPTY); } ResultSequence arg2 = ResultBuffer.EMPTY; if (argiter.MoveNext()) { arg2 = (ResultSequence)argiter.Current; } XSTime time = (XSTime)arg1.first(); XSDayTimeDuration timezone = null; if (arg2.empty()) { if (time.timezoned()) { XSTime localized = new XSTime(time.calendar(), null); return(localized); } else { return(arg1); } } XMLGregorianCalendar xmlCalendar = null; if (time.tz() != null) { xmlCalendar = _datatypeFactory.newXMLGregorianCalendar((GregorianCalendar)time.normalizeCalendar(time.calendar(), time.tz())); } else { xmlCalendar = _datatypeFactory.newXMLGregorianCalendarTime(time.hour(), time.minute(), (int)time.second(), 0); } timezone = (XSDayTimeDuration)arg2.first(); if (timezone.lt(minDuration, dc) || timezone.gt(maxDuration, dc)) { throw DynamicError.invalidTimezone(); } if (time.tz() == null) { return(new XSTime(time.calendar(), timezone)); } Duration duration = _datatypeFactory.newDuration(timezone.StringValue); xmlCalendar.add(duration); return(new XSTime(xmlCalendar.toGregorianCalendar(), timezone)); }