示例#1
0
        public static TimeValue Add(TimeValue tm, DayTimeDurationValue duration)
        {
            DateTimeValue dat;

            if (tm.IsLocal)
            {
                dat = new DateTimeValue(false, DateTime.Today, tm.Value.DateTime);
            }
            else
            {
                dat = new DateTimeValue(false, DateTime.Today, tm.Value.DateTime, tm.Value.Offset);
            }
            DateTime dt    = DateTimeValue.Add(dat, duration).Value.DateTime;
            DateTime today = DateTime.Today;

            dt = new DateTime(today.Year, today.Month, today.Day, dt.Hour, dt.Minute, dt.Second, dt.Millisecond);
            if (tm.IsLocal)
            {
                return(new TimeValue(dt));
            }
            else
            {
                return(new TimeValue(new DateTimeOffset(dt, tm.Value.Offset)));
            }
        }
示例#2
0
 private static decimal Divide(DayTimeDurationValue a, DayTimeDurationValue b)
 {
     if (b.LowPartValue == TimeSpan.Zero)
     {
         throw new XPath2Exception("FOAR0001", Properties.Resources.FOAR0001);
     }
     return((decimal)a.LowPartValue.Ticks / (decimal)b.LowPartValue.Ticks);
 }
示例#3
0
        public static DayTimeDurationValue Multiply(DayTimeDurationValue a, double b)
        {
            if (Double.IsNaN(b) || Double.IsNegativeInfinity(b) || Double.IsPositiveInfinity(b))
            {
                throw new XPath2Exception("FOCA0005", Properties.Resources.FOCA0005);
            }
            long timespan = (long)(a.LowPartValue.Ticks * b);

            return(new DayTimeDurationValue(new TimeSpan(timespan)));
        }
示例#4
0
        int IComparable.CompareTo(object obj)
        {
            DayTimeDurationValue other = obj as DayTimeDurationValue;

            if (other == null)
            {
                throw new ArgumentException("obj");
            }
            return(LowPartValue.CompareTo(other.LowPartValue));
        }
示例#5
0
 protected override ValueProxy Mul(ValueProxy value)
 {
     if (value.IsNumeric())
     {
         return(new Proxy(DayTimeDurationValue.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));
 }
示例#6
0
        public static DayTimeDurationValue Divide(DayTimeDurationValue a, double b)
        {
            if (b == 0.0)
            {
                throw new XPath2Exception("FOAR0001", Properties.Resources.FOAR0001);
            }
            if (Double.IsNaN(b))
            {
                throw new XPath2Exception("FOCA0005", Properties.Resources.FOCA0005);
            }
            long timespan = (long)(a.LowPartValue.Ticks / b);

            return(new DayTimeDurationValue(new TimeSpan(timespan)));
        }
示例#7
0
 protected override ValueProxy Div(ValueProxy value)
 {
     if (value.IsNumeric())
     {
         return(new Proxy(DayTimeDurationValue.Divide(_value, Convert.ToDouble(value))));
     }
     else if (value.GetValueCode() == DayTimeDurationValue.ProxyValueCode)
     {
         return(new DecimalProxy(DayTimeDurationValue.Divide(_value, (DayTimeDurationValue)value.Value)));
     }
     else
     {
         throw new XPath2Exception("", Properties.Resources.BinaryOperatorNotDefined, "op:div",
                                   new SequenceType(_value.GetType(), XmlTypeCardinality.One),
                                   new SequenceType(value.Value.GetType(), XmlTypeCardinality.One));
     }
 }
示例#8
0
        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));
            }
        }
示例#9
0
 public static DateValue Add(DateValue dat, DayTimeDurationValue duration)
 {
     try
     {
         decimal seconds = (decimal)duration.LowPartValue.Ticks / TimeSpan.TicksPerSecond;
         decimal julian  = dat.ToJulianInstant();
         julian += seconds;
         DateTimeValue dt = DateTimeValue.CreateFromJulianInstant(julian);
         if (dat.IsLocal)
         {
             return(new DateValue(dt.S, dt.Value.Date));
         }
         else
         {
             return(new DateValue(dt.S, new DateTimeOffset(dt.Value.Date, dat.Value.Offset)));
         }
     }
     catch (ArgumentOutOfRangeException)
     {
         throw new XPath2Exception("FODT0001", Properties.Resources.FODT0001);
     }
 }
示例#10
0
 public Proxy(DayTimeDurationValue value)
 {
     _value = value;
 }