Ejemplo n.º 1
0
        } // method GetPatternForFormatCharacter

        /// <summary>
        /// Returns DvDateTime instance with the given magnitude
        /// </summary>
        /// <param name="magnitude">magnitude is the numeric value of the date as seconds
        /// since the calendar origin point 1/1/0000</param>
        /// <returns></returns>
        internal static DvTemporal <DvDateTime> GetDateTimeByMagnitude(double magnitude)
        {
            DesignByContract.Check.Require(magnitude >= TimeDefinitions.hoursInDay * TimeDefinitions.minutesInHour
                                           * TimeDefinitions.secondsInMinute);

            double secondsInDay = TimeDefinitions.secondsInMinute * TimeDefinitions.minutesInHour
                                  * TimeDefinitions.hoursInDay;

            //int daysInMagnitude = (int)(Math.Truncate(magnitude / secondsInDay));
            double          daysInMagnitude = magnitude / secondsInDay;
            DvDate          dvDate          = DvDate.GetDateByMagnitude(daysInMagnitude);
            Iso8601DateTime isoDateTime     = new Iso8601DateTime(dvDate.Value);

            //double remainder = magnitude - daysInMagnitude * secondsInDay;
            double remainder = magnitude - isoDateTime.GetDateTimeSeconds();

            if (remainder != 0 && !isoDateTime.DayUnknown && isoDateTime.Day > TimeDefinitions.nominalDaysInMonth)
            {
                remainder += (isoDateTime.Day - TimeDefinitions.nominalDaysInMonth) * TimeDefinitions.hoursInDay * TimeDefinitions.minutesInHour * TimeDefinitions.secondsInMinute;
            }

            if (remainder < 0)
            {
                dvDate      = DvDate.GetDateByMagnitude((isoDateTime.GetDateTimeSeconds() - secondsInDay) / secondsInDay);
                isoDateTime = new Iso8601DateTime(dvDate.Value);
                remainder   = magnitude - isoDateTime.GetDateTimeSeconds();
            }

            if (remainder == 86400)
            {
                dvDate      = DvDate.GetDateByMagnitude((isoDateTime.GetDateTimeSeconds() + remainder) / secondsInDay);
                isoDateTime = new Iso8601DateTime(dvDate.Value);

                remainder = magnitude - isoDateTime.GetDateTimeSeconds();
            }

            DvTime dvTime = null;

            if (remainder > 0)
            {
                dvTime = DvTime.GetTimeByMagnitude(remainder);

                return(new DvDateTime(dvDate.Value + "T" + dvTime.Value));
            }
            return(new DvDateTime(dvDate.Value));
        }
Ejemplo n.º 2
0
 private DvTime AppendTimeZone(DvTime time)
 {
     if (this.isoDateTime.Iso8601TimeZone != null && Math.Abs(this.isoDateTime.Iso8601TimeZone.GetTimeZoneSeconds()) > 0)
     {
         Iso8601Time isoTime = new Iso8601Time(time.Value);
         if (isoTime.HasFractionalSecond)
         {
             time = new DvTime(isoTime.Hour, isoTime.Minute, isoTime.Second, isoTime.FractionalSecond,
                               this.isoDateTime.Iso8601TimeZone.Sign, this.isoDateTime.Iso8601TimeZone.Hour,
                               this.isoDateTime.Iso8601TimeZone.Minute);
         }
         else
         {
             if (!isoTime.SecondUnknown)
             {
                 time = new DvTime(isoTime.Hour, isoTime.Minute, isoTime.Second, 0,
                                   this.isoDateTime.Iso8601TimeZone.Sign, this.isoDateTime.Iso8601TimeZone.Hour,
                                   this.isoDateTime.Iso8601TimeZone.Minute);
             }
             else
             {
                 if (!isoTime.MinuteUnknown)
                 {
                     time = new DvTime(isoTime.Hour, isoTime.Minute, -1, 0,
                                       this.isoDateTime.Iso8601TimeZone.Sign, this.isoDateTime.Iso8601TimeZone.Hour,
                                       this.isoDateTime.Iso8601TimeZone.Minute);
                 }
                 else
                 {
                     throw new ApplicationException("should not get here.");
                 }
             }
         }
     }
     return(time);
 }