public static YearMonthDurationValue Multiply(YearMonthDurationValue a, double b) { if (Double.IsNaN(b) || Double.IsNegativeInfinity(b) || Double.IsPositiveInfinity(b)) { throw new XPath2Exception("FOCA0005", Resources.FOCA0005); } int month = (int)Math.Floor(0.5 + DaysToMonth(a.HighPartValue.Days) * b); return(new YearMonthDurationValue(new TimeSpan(MonthToDays(month), 0, 0, 0))); }
int IComparable.CompareTo(object obj) { YearMonthDurationValue other = obj as YearMonthDurationValue; if (other == null) { throw new ArgumentException("obj"); } return(HighPartValue.CompareTo(other.HighPartValue)); }
protected override ValueProxy Mul(ValueProxy value) { if (value.IsNumeric()) { return(new Proxy(YearMonthDurationValue.Multiply(_value, Convert.ToDouble(value)))); } throw new XPath2Exception("", Properties.Resources.BinaryOperatorNotDefined, "op:mul", new SequenceType(_value.GetType(), XmlTypeCardinality.One), new SequenceType(value.Value.GetType(), XmlTypeCardinality.One)); }
public static decimal Divide(YearMonthDurationValue a, YearMonthDurationValue b) { int month1 = DaysToMonth(a.HighPartValue.Days); int month2 = DaysToMonth(b.HighPartValue.Days); if (month2 == 0) { throw new XPath2Exception("FOAR0001", Resources.FOAR0001); } return((decimal)month1 / (decimal)month2); }
public static YearMonthDurationValue Divide(YearMonthDurationValue a, double b) { if (b == 0.0) { throw new XPath2Exception("FOAR0001", Resources.FOAR0001); } if (Double.IsNaN(b)) { throw new XPath2Exception("FOCA0005", Resources.FOCA0005); } int month = (int)Math.Floor(0.5 + DaysToMonth(a.HighPartValue.Days) / b); return(new YearMonthDurationValue(new TimeSpan(MonthToDays(month), 0, 0, 0))); }
protected override ValueProxy Div(ValueProxy value) { if (value.IsNumeric()) { return(new Proxy(YearMonthDurationValue.Divide(_value, Convert.ToDouble(value)))); } else if (value.GetValueCode() == YearMonthDurationValue.ProxyValueCode) { return(new DecimalProxy(YearMonthDurationValue.Divide(_value, (YearMonthDurationValue)value.Value))); } else { throw new XPath2Exception("", Properties.Resources.BinaryOperatorNotDefined, "op:div", new SequenceType(_value.GetType(), XmlTypeCardinality.One), new SequenceType(value.Value.GetType(), XmlTypeCardinality.One)); } }
protected override ValueProxy Mul(ValueProxy val) { switch (val.GetValueCode()) { case YearMonthDurationValue.ProxyValueCode: return(new YearMonthDurationValue.Proxy( YearMonthDurationValue.Multiply((YearMonthDurationValue)val.Value, Convert.ToDouble(_value)))); case DayTimeDurationValue.ProxyValueCode: return(new DayTimeDurationValue.Proxy( DayTimeDurationValue.Multiply((DayTimeDurationValue)val.Value, Convert.ToDouble(_value)))); default: throw new XPath2Exception("", Resources.BinaryOperatorNotDefined, "op:mul", new SequenceType(Value.GetType(), XmlTypeCardinality.One), new SequenceType(val.Value.GetType(), XmlTypeCardinality.One)); } }
public static DateValue Add(DateValue dat, YearMonthDurationValue duration) { try { Calendar calender = CultureInfo.InvariantCulture.Calendar; DateTime dt = dat.Value.DateTime; int year = dat.S ? -dt.Year : dt.Year - 1; int m = (dt.Month - 1) + duration.Months; year = year + duration.Years + m / 12; if (year >= 0) { year = year + 1; } m = m % 12; if (m < 0) { m += 12; year -= 1; } m++; int day = Math.Min(dt.Day, calender.GetDaysInMonth(Math.Abs(year), m)); if (year < 0) { dt = new DateTime(-year, m, day); } else { dt = new DateTime(year, m, day); } if (dat.IsLocal) { return(new DateValue(year < 0, dt)); } else { return(new DateValue(year < 0, new DateTimeOffset(dt, dat.Value.Offset))); } } catch (ArgumentOutOfRangeException) { throw new XPath2Exception("FODT0001", Properties.Resources.FODT0001); } }
public Proxy(YearMonthDurationValue value) { _value = value; }