/// <summary>
        /// Initializes this transition based on the specified transition time.
        /// </summary>
        /// <param name="transitionTime">The transition time to initialize from.</param>
        internal override void InitializeFromTransitionTime(TransitionTime transitionTime)
        {
            base.InitializeFromTransitionTime(transitionTime);

            this.timeOffset = transitionTime.TimeOfDay.TimeOfDay;
            this.month      = transitionTime.Month;
        }
            /// <summary>
            /// Helper method to serialize a TimeZoneInfo.TransitionTime object.
            /// </summary>
            private static void SerializeTransitionTime(TransitionTime time, StringBuilder serializedText)
            {
                serializedText.Append(Lhs);
                int fixedDate = (time.IsFixedDateRule ? 1 : 0);

                serializedText.Append(fixedDate.ToString(CultureInfo.InvariantCulture));
                serializedText.Append(Sep);

                if (time.IsFixedDateRule)
                {
                    serializedText.Append(SerializeSubstitute(time.TimeOfDay.ToString(TimeOfDayFormat, DateTimeFormatInfo.InvariantInfo)));
                    serializedText.Append(Sep);
                    serializedText.Append(SerializeSubstitute(time.Month.ToString(CultureInfo.InvariantCulture)));
                    serializedText.Append(Sep);
                    serializedText.Append(SerializeSubstitute(time.Day.ToString(CultureInfo.InvariantCulture)));
                    serializedText.Append(Sep);
                }
                else
                {
                    serializedText.Append(SerializeSubstitute(time.TimeOfDay.ToString(TimeOfDayFormat, DateTimeFormatInfo.InvariantInfo)));
                    serializedText.Append(Sep);
                    serializedText.Append(SerializeSubstitute(time.Month.ToString(CultureInfo.InvariantCulture)));
                    serializedText.Append(Sep);
                    serializedText.Append(SerializeSubstitute(time.Week.ToString(CultureInfo.InvariantCulture)));
                    serializedText.Append(Sep);
                    serializedText.Append(SerializeSubstitute(((int)time.DayOfWeek).ToString(CultureInfo.InvariantCulture)));
                    serializedText.Append(Sep);
                }
                serializedText.Append(Rhs);
            }
        /// <summary>
        /// Initializes a new instance of the <see cref="LegacyAvailabilityTimeZoneTime"/> class.
        /// </summary>
        /// <param name="transitionTime">The transition time used to initialize this instance.</param>
        /// <param name="delta">The offset used to initialize this instance.</param>
        internal LegacyAvailabilityTimeZoneTime(TransitionTime transitionTime, TimeSpan delta)
            : this()
        {
            this.delta = delta;

            if (transitionTime.IsFixedDateRule)
            {
                // TimeZoneInfo doesn't support an actual year. Fixed date transitions occur at the same
                // date every year the adjustment rule the transition belongs to applies. The best thing
                // we can do here is use the current year.
                this.year      = DateTime.Today.Year;
                this.month     = transitionTime.Month;
                this.dayOrder  = transitionTime.Day;
                this.timeOfDay = transitionTime.TimeOfDay.TimeOfDay;
            }
            else
            {
                // For floating rules, the mapping is direct.
                this.year         = 0;
                this.month        = transitionTime.Month;
                this.dayOfTheWeek = EwsUtilities.SystemToEwsDayOfTheWeek(transitionTime.DayOfWeek);
                this.dayOrder     = transitionTime.Week;
                this.timeOfDay    = transitionTime.TimeOfDay.TimeOfDay;
            }
        }
예제 #4
0
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            XmlDocument document = new XmlDocument();
            XmlElement  root     = document.CreateElement("slideshow");

            if (DisplayTime > 0)
            {
                root.SetAttribute("displayTime", DisplayTime.ToString());
            }

            if (TransitionTime > 0)
            {
                root.SetAttribute("transitionTime", TransitionTime.ToString());
            }

            var valid    = Slides.Where(slide => !string.IsNullOrEmpty(slide.ImageUrl));
            var elements = valid.Select(slide => slide.ToXmlElement(document)).ToList();

            elements.ForEach(element => root.AppendChild(element));

            document.AppendChild(root);

            ConfigXml      = HttpUtility.UrlEncode(document.OuterXml);
            FlashAvailable = elements.Count > 0;
        }
예제 #5
0
            private AdjustmentRule(SerializationInfo info, StreamingContext context)
            {
                if (info == null)
                {
                    throw new ArgumentNullException(nameof(info));
                }

                _dateStart               = (DateTime)info.GetValue("DateStart", typeof(DateTime)) !;                           // Do not rename (binary serialization)
                _dateEnd                 = (DateTime)info.GetValue("DateEnd", typeof(DateTime)) !;                             // Do not rename (binary serialization)
                _daylightDelta           = (TimeSpan)info.GetValue("DaylightDelta", typeof(TimeSpan)) !;                       // Do not rename (binary serialization)
                _daylightTransitionStart = (TransitionTime)info.GetValue("DaylightTransitionStart", typeof(TransitionTime)) !; // Do not rename (binary serialization)
                _daylightTransitionEnd   = (TransitionTime)info.GetValue("DaylightTransitionEnd", typeof(TransitionTime)) !;   // Do not rename (binary serialization)

                object?o = info.GetValueNoThrow("BaseUtcOffsetDelta", typeof(TimeSpan));                                       // Do not rename (binary serialization)

                if (o != null)
                {
                    _baseUtcOffsetDelta = (TimeSpan)o;
                }

                o = info.GetValueNoThrow("NoDaylightTransitions", typeof(bool)); // Do not rename (binary serialization)
                if (o != null)
                {
                    _noDaylightTransitions = (bool)o;
                }
            }
예제 #6
0
        // TZFILE(5)                   BSD File Formats Manual                  TZFILE(5)
        //
        // NAME
        //      tzfile -- timezone information
        //
        // SYNOPSIS
        //      #include "/usr/src/lib/libc/stdtime/tzfile.h"
        //
        // DESCRIPTION
        //      The time zone information files used by tzset(3) begin with the magic
        //      characters ``TZif'' to identify them as time zone information files, fol-
        //      lowed by sixteen bytes reserved for future use, followed by four four-
        //      byte values written in a ``standard'' byte order (the high-order byte of
        //      the value is written first).  These values are, in order:
        //
        //      tzh_ttisgmtcnt  The number of UTC/local indicators stored in the file.
        //      tzh_ttisstdcnt  The number of standard/wall indicators stored in the
        //                      file.
        //      tzh_leapcnt     The number of leap seconds for which data is stored in
        //                      the file.
        //      tzh_timecnt     The number of ``transition times'' for which data is
        //                      stored in the file.
        //      tzh_typecnt     The number of ``local time types'' for which data is
        //                      stored in the file (must not be zero).
        //      tzh_charcnt     The number of characters of ``time zone abbreviation
        //                      strings'' stored in the file.
        //
        //      The above header is followed by tzh_timecnt four-byte values of type
        //      long, sorted in ascending order.  These values are written in ``stan-
        //      dard'' byte order.  Each is used as a transition time (as returned by
        //      time(3)) at which the rules for computing local time change.  Next come
        //      tzh_timecnt one-byte values of type unsigned char; each one tells which
        //      of the different types of ``local time'' types described in the file is
        //      associated with the same-indexed transition time.  These values serve as
        //      indices into an array of ttinfo structures that appears next in the file;
        //      these structures are defined as follows:
        //
        //            struct ttinfo {
        //                    long    tt_gmtoff;
        //                    int     tt_isdst;
        //                    unsigned int    tt_abbrind;
        //            };
        //
        //      Each structure is written as a four-byte value for tt_gmtoff of type
        //      long, in a standard byte order, followed by a one-byte value for tt_isdst
        //      and a one-byte value for tt_abbrind.  In each structure, tt_gmtoff gives
        //      the number of seconds to be added to UTC, tt_isdst tells whether t_isdst
        //      should be set by localtime(3) and tt_abbrind serves as an index into the
        //      array of time zone abbreviation characters that follow the ttinfo struc-
        //      ture(s) in the file.
        //
        //      Then there are tzh_leapcnt pairs of four-byte values, written in standard
        //      byte order; the first value of each pair gives the time (as returned by
        //      time(3)) at which a leap second occurs; the second gives the total number
        //      of leap seconds to be applied after the given time.  The pairs of values
        //      are sorted in ascending order by time.b
        //
        //      Then there are tzh_ttisstdcnt standard/wall indicators, each stored as a
        //      one-byte value; they tell whether the transition times associated with
        //      local time types were specified as standard time or wall clock time, and
        //      are used when a time zone file is used in handling POSIX-style time zone
        //      environment variables.
        //
        //      Finally there are tzh_ttisgmtcnt UTC/local indicators, each stored as a
        //      one-byte value; they tell whether the transition times associated with
        //      local time types were specified as UTC or local time, and are used when a
        //      time zone file is used in handling POSIX-style time zone environment
        //      variables.
        //
        //      localtime uses the first standard-time ttinfo structure in the file (or
        //      simply the first ttinfo structure in the absence of a standard-time
        //      structure) if either tzh_timecnt is zero or the time argument is less
        //      than the first transition time recorded in the file.
        //
        // SEE ALSO
        //      ctime(3), time2posix(3), zic(8)
        //
        // BSD                           September 13, 1994                           BSD
        //
        //
        //
        // TIME(3)                  BSD Library Functions Manual                  TIME(3)
        //
        // NAME
        //      time -- get time of day
        //
        // LIBRARY
        //      Standard C Library (libc, -lc)
        //
        // SYNOPSIS
        //      #include <time.h>
        //
        //      time_t
        //      time(time_t *tloc);
        //
        // DESCRIPTION
        //      The time() function returns the value of time in seconds since 0 hours, 0
        //      minutes, 0 seconds, January 1, 1970, Coordinated Universal Time, without
        //      including leap seconds.  If an error occurs, time() returns the value
        //      (time_t)-1.
        //
        //      The return value is also stored in *tloc, provided that tloc is non-null.
        //
        // ERRORS
        //      The time() function may fail for any of the reasons described in
        //      gettimeofday(2).
        //
        // SEE ALSO
        //      gettimeofday(2), ctime(3)
        //
        // STANDARDS
        //      The time function conforms to IEEE Std 1003.1-2001 (``POSIX.1'').
        //
        // BUGS
        //      Neither ISO/IEC 9899:1999 (``ISO C99'') nor IEEE Std 1003.1-2001
        //      (``POSIX.1'') requires time() to set errno on failure; thus, it is impos-
        //      sible for an application to distinguish the valid time value -1 (repre-
        //      senting the last UTC second of 1969) from the error return value.
        //
        //      Systems conforming to earlier versions of the C and POSIX standards
        //      (including older versions of FreeBSD) did not set *tloc in the error
        //      case.
        //
        // HISTORY
        //      A time() function appeared in Version 6 AT&T UNIX.
        //
        // BSD                              July 18, 2003                             BSD
        //
        //

        //
        // TZif_CalculateTransitionTime -
        //
        // Example inputs:
        // -----------------
        // utc               =     1918-03-31T10:00:00.0000000Z
        // transitionType    =     {-08:00:00  DST=False,  Index 4}
        // standardTime      =     False
        // gmtTime           =     False
        //
        private static TransitionTime TZif_CalculateTransitionTime(DateTime utc, TimeSpan offset,
                                                                   TZifType transitionType, Boolean standardTime,
                                                                   Boolean gmtTime, out DateTime ruleDate)
        {
            // convert from UTC to local clock time
            Int64 ticks = utc.Ticks + offset.Ticks;

            if (ticks > DateTime.MaxValue.Ticks)
            {
                utc = DateTime.MaxValue;
            }
            else if (ticks < DateTime.MinValue.Ticks)
            {
                utc = DateTime.MinValue;
            }
            else
            {
                utc = new DateTime(ticks);
            }

            DateTime timeOfDay = new DateTime(1, 1, 1, utc.Hour, utc.Minute, utc.Second, utc.Millisecond);
            int      month     = utc.Month;
            int      day       = utc.Day;

            ruleDate = new DateTime(utc.Year, month, day);
            // FUTURE: take standardTime/gmtTime into account
            return(TransitionTime.CreateFixedDateRule(timeOfDay, month, day));
        }
 /// <summary>
 /// Creates a timw zone transition time.
 /// </summary>
 /// <returns>A TimeZoneInfo.TransitionTime.</returns>
 internal override TransitionTime CreateTransitionTime()
 {
     return(TransitionTime.CreateFixedDateRule(
                new DateTime(this.TimeOffset.Ticks),
                this.Month,
                this.DayOfMonth));
 }
예제 #8
0
 private AdjustmentRule(DateTime dateStart, DateTime dateEnd, TimeSpan daylightDelta, TransitionTime daylightTransitionStart, TransitionTime daylightTransitionEnd)
 {
     if (dateStart.Kind != 0 || dateEnd.Kind != 0)
     {
         throw new ArgumentException("the Kind property of dateStart or dateEnd parameter does not equal DateTimeKind.Unspecified");
     }
     if (daylightTransitionStart == daylightTransitionEnd)
     {
         throw new ArgumentException("daylightTransitionStart parameter cannot equal daylightTransitionEnd parameter");
     }
     if (dateStart.Ticks % 864000000000L != 0L || dateEnd.Ticks % 864000000000L != 0L)
     {
         throw new ArgumentException("dateStart or dateEnd parameter includes a time of day value");
     }
     if (dateEnd < dateStart)
     {
         throw new ArgumentOutOfRangeException("dateEnd is earlier than dateStart");
     }
     if (daylightDelta > new TimeSpan(14, 0, 0) || daylightDelta < new TimeSpan(-14, 0, 0))
     {
         throw new ArgumentOutOfRangeException("daylightDelta is less than -14 or greater than 14 hours");
     }
     if (daylightDelta.Ticks % 10000000 != 0L)
     {
         throw new ArgumentOutOfRangeException("daylightDelta parameter does not represent a whole number of seconds");
     }
     this.dateStart               = dateStart;
     this.dateEnd                 = dateEnd;
     this.daylightDelta           = daylightDelta;
     this.daylightTransitionStart = daylightTransitionStart;
     this.daylightTransitionEnd   = daylightTransitionEnd;
 }
 /// <summary>
 /// Creates a timw zone transition time.
 /// </summary>
 /// <returns>A TimeZoneInfo.TransitionTime.</returns>
 internal override TransitionTime CreateTransitionTime()
 {
     return(TransitionTime.CreateFloatingDateRule(
                new DateTime(this.TimeOffset.Ticks),
                this.Month,
                this.WeekIndex == -1 ? 5 : this.WeekIndex,
                EwsUtilities.EwsToSystemDayOfWeek(this.DayOfTheWeek)));
 }
예제 #10
0
        /// <summary>
        /// Returns true if HistoryItem instances are equal
        /// </summary>
        /// <param name="other">Instance of HistoryItem to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(HistoryItem other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Id == other.Id ||
                     Id != null &&
                     Id.Equals(other.Id)
                     ) &&
                 (
                     ProcessId == other.ProcessId ||
                     ProcessId != null &&
                     ProcessId.Equals(other.ProcessId)
                 ) &&
                 (
                     IdentityId == other.IdentityId ||
                     IdentityId != null &&
                     IdentityId.Equals(other.IdentityId)
                 ) &&
                 (
                     AllowedToEmployeeNames == other.AllowedToEmployeeNames ||
                     AllowedToEmployeeNames != null &&
                     AllowedToEmployeeNames.Equals(other.AllowedToEmployeeNames)
                 ) &&
                 (
                     TransitionTime == other.TransitionTime ||
                     TransitionTime != null &&
                     TransitionTime.Equals(other.TransitionTime)
                 ) &&
                 (
                     Order == other.Order ||
                     Order != null &&
                     Order.Equals(other.Order)
                 ) &&
                 (
                     InitialState == other.InitialState ||
                     InitialState != null &&
                     InitialState.Equals(other.InitialState)
                 ) &&
                 (
                     DestinationState == other.DestinationState ||
                     DestinationState != null &&
                     DestinationState.Equals(other.DestinationState)
                 ) &&
                 (
                     Command == other.Command ||
                     Command != null &&
                     Command.Equals(other.Command)
                 ));
        }
예제 #11
0
 public static AdjustmentRule CreateAdjustmentRule(
     DateTime dateStart,
     DateTime dateEnd,
     TimeSpan daylightDelta,
     TransitionTime daylightTransitionStart,
     TransitionTime daylightTransitionEnd)
 {
     return(new AdjustmentRule(dateStart, dateEnd, daylightDelta, daylightTransitionStart, daylightTransitionEnd));
 }
        /// <summary>
        /// Initializes this transition based on the specified transition time.
        /// </summary>
        /// <param name="transitionTime">The transition time to initialize from.</param>
        internal override void InitializeFromTransitionTime(TransitionTime transitionTime)
        {
            base.InitializeFromTransitionTime(transitionTime);

            this.dayOfTheWeek = EwsUtilities.SystemToEwsDayOfTheWeek(transitionTime.DayOfWeek);

            // TimeZoneInfo uses week indices from 1 to 5, 5 being the last week of the month.
            // EWS uses -1 to denote the last week of the month.
            this.weekIndex = transitionTime.Week == 5 ? -1 : transitionTime.Week;
        }
 private static string CreateCode(TransitionTime t)
 {
     if (t.IsFixedDateRule)
     {
         return($"T({t.TimeOfDay.ToBinary()}, {t.Month}, {t.Day})");
     }
     else
     {
         return($"T({t.TimeOfDay.ToBinary()}, {t.Month}, {t.Week}, DayOfWeek.{t.DayOfWeek})");
     }
 }
예제 #14
0
        /// <summary>
        /// Converts a Win32Native.RegistryTimeZoneInformation (REG_TZI_FORMAT struct) to an AdjustmentRule.
        /// </summary>
        private static AdjustmentRule CreateAdjustmentRuleFromTimeZoneInformation(Win32Native.RegistryTimeZoneInformation timeZoneInformation, DateTime startDate, DateTime endDate, int defaultBaseUtcOffset)
        {
            bool supportsDst = timeZoneInformation.StandardDate.Month != 0;

            if (!supportsDst)
            {
                if (timeZoneInformation.Bias == defaultBaseUtcOffset)
                {
                    // this rule will not contain any information to be used to adjust dates. just ignore it
                    return(null);
                }

                return(AdjustmentRule.CreateAdjustmentRule(
                           startDate,
                           endDate,
                           TimeSpan.Zero, // no daylight saving transition
                           TransitionTime.CreateFixedDateRule(DateTime.MinValue, 1, 1),
                           TransitionTime.CreateFixedDateRule(DateTime.MinValue.AddMilliseconds(1), 1, 1),
                           new TimeSpan(0, defaultBaseUtcOffset - timeZoneInformation.Bias, 0), // Bias delta is all what we need from this rule
                           noDaylightTransitions: false));
            }

            //
            // Create an AdjustmentRule with TransitionTime objects
            //
            TransitionTime daylightTransitionStart;

            if (!TransitionTimeFromTimeZoneInformation(timeZoneInformation, out daylightTransitionStart, readStartDate: true))
            {
                return(null);
            }

            TransitionTime daylightTransitionEnd;

            if (!TransitionTimeFromTimeZoneInformation(timeZoneInformation, out daylightTransitionEnd, readStartDate: false))
            {
                return(null);
            }

            if (daylightTransitionStart.Equals(daylightTransitionEnd))
            {
                // this happens when the time zone does support DST but the OS has DST disabled
                return(null);
            }

            return(AdjustmentRule.CreateAdjustmentRule(
                       startDate,
                       endDate,
                       new TimeSpan(0, -timeZoneInformation.DaylightBias, 0),
                       daylightTransitionStart,
                       daylightTransitionEnd,
                       new TimeSpan(0, defaultBaseUtcOffset - timeZoneInformation.Bias, 0),
                       noDaylightTransitions: false));
        }
예제 #15
0
 private AdjustmentRule(SerializationInfo info, StreamingContext context)
 {
     if (info == null)
     {
         throw new ArgumentNullException("info");
     }
     dateStart               = (DateTime)info.GetValue("DateStart", typeof(DateTime));
     dateEnd                 = (DateTime)info.GetValue("DateEnd", typeof(DateTime));
     daylightDelta           = (TimeSpan)info.GetValue("DaylightDelta", typeof(TimeSpan));
     daylightTransitionStart = (TimeZoneInfo.TransitionTime)info.GetValue("DaylightTransitionStart", typeof(TimeZoneInfo.TransitionTime));
     daylightTransitionEnd   = (TimeZoneInfo.TransitionTime)info.GetValue("DaylightTransitionEnd", typeof(TimeZoneInfo.TransitionTime));
 }
        public async Task Object_TimeZoneInfo_AdjustmentRule()
        {
            var a = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(
                new DateTime(1, 1, 1, 0, 0, 0),
                new DateTime(2, 1, 1, 0, 0, 0),
                TimeSpan.FromHours(1),
                TransitionTime.CreateFixedDateRule(new DateTime(1, 1, 1, 2, 0, 0), 3, 15),
                TransitionTime.CreateFixedDateRule(new DateTime(1, 1, 1, 2, 0, 0), 6, 15)
                );

            await Test(a, (b) => Assert.Equal(a, b));
        }
예제 #17
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (ProcessId != null)
         {
             hashCode = hashCode * 59 + ProcessId.GetHashCode();
         }
         if (ActorIdentityId != null)
         {
             hashCode = hashCode * 59 + ActorIdentityId.GetHashCode();
         }
         if (ExecutorIdentityId != null)
         {
             hashCode = hashCode * 59 + ExecutorIdentityId.GetHashCode();
         }
         if (FromActivityName != null)
         {
             hashCode = hashCode * 59 + FromActivityName.GetHashCode();
         }
         if (FromStateName != null)
         {
             hashCode = hashCode * 59 + FromStateName.GetHashCode();
         }
         if (IsFinalised != null)
         {
             hashCode = hashCode * 59 + IsFinalised.GetHashCode();
         }
         if (ToActivityName != null)
         {
             hashCode = hashCode * 59 + ToActivityName.GetHashCode();
         }
         if (ToStateName != null)
         {
             hashCode = hashCode * 59 + ToStateName.GetHashCode();
         }
         if (TransitionClassifier != null)
         {
             hashCode = hashCode * 59 + TransitionClassifier.GetHashCode();
         }
         if (TransitionTime != null)
         {
             hashCode = hashCode * 59 + TransitionTime.GetHashCode();
         }
         if (TriggerName != null)
         {
             hashCode = hashCode * 59 + TriggerName.GetHashCode();
         }
         return(hashCode);
     }
 }
예제 #18
0
            /// <summary>
            /// Helper function that performs all of the validation checks for the actory methods and deserialization callback.
            /// </summary>
            private static void ValidateAdjustmentRule(
                DateTime dateStart,
                DateTime dateEnd,
                TimeSpan daylightDelta,
                TransitionTime daylightTransitionStart,
                TransitionTime daylightTransitionEnd,
                bool noDaylightTransitions)
            {
                if (dateStart.Kind != DateTimeKind.Unspecified && dateStart.Kind != DateTimeKind.Utc)
                {
                    throw new ArgumentException(SR.Argument_DateTimeKindMustBeUnspecifiedOrUtc, nameof(dateStart));
                }

                if (dateEnd.Kind != DateTimeKind.Unspecified && dateEnd.Kind != DateTimeKind.Utc)
                {
                    throw new ArgumentException(SR.Argument_DateTimeKindMustBeUnspecifiedOrUtc, nameof(dateEnd));
                }

                if (daylightTransitionStart.Equals(daylightTransitionEnd) && !noDaylightTransitions)
                {
                    throw new ArgumentException(SR.Argument_TransitionTimesAreIdentical, nameof(daylightTransitionEnd));
                }

                if (dateStart > dateEnd)
                {
                    throw new ArgumentException(SR.Argument_OutOfOrderDateTimes, nameof(dateStart));
                }

                // This cannot use UtcOffsetOutOfRange to account for the scenario where Samoa moved across the International Date Line,
                // which caused their current BaseUtcOffset to be +13. But on the other side of the line it was UTC-11 (+1 for daylight).
                // So when trying to describe DaylightDeltas for those times, the DaylightDelta needs
                // to be -23 (what it takes to go from UTC+13 to UTC-10)
                if (daylightDelta.TotalHours < -23.0 || daylightDelta.TotalHours > 14.0)
                {
                    throw new ArgumentOutOfRangeException(nameof(daylightDelta), daylightDelta, SR.ArgumentOutOfRange_UtcOffset);
                }

                if (daylightDelta.Ticks % TimeSpan.TicksPerMinute != 0)
                {
                    throw new ArgumentException(SR.Argument_TimeSpanHasSeconds, nameof(daylightDelta));
                }

                if (dateStart != DateTime.MinValue && dateStart.Kind == DateTimeKind.Unspecified && dateStart.TimeOfDay != TimeSpan.Zero)
                {
                    throw new ArgumentException(SR.Argument_DateTimeHasTimeOfDay, nameof(dateStart));
                }

                if (dateEnd != DateTime.MaxValue && dateEnd.Kind == DateTimeKind.Unspecified && dateEnd.TimeOfDay != TimeSpan.Zero)
                {
                    throw new ArgumentException(SR.Argument_DateTimeHasTimeOfDay, nameof(dateEnd));
                }
                Contract.EndContractBlock();
            }
예제 #19
0
        internal static AdjustmentRule CreateAdjustmentRuleFromTimeZoneInformation(ref DYNAMIC_TIME_ZONE_INFORMATION timeZoneInformation, DateTime startDate, DateTime endDate, int defaultBaseUtcOffset)
        {
            bool supportsDst = (timeZoneInformation.TZI.StandardDate.wMonth != 0);

            if (!supportsDst)
            {
                if (timeZoneInformation.TZI.Bias == defaultBaseUtcOffset)
                {
                    // this rule will not contain any information to be used to adjust dates. just ignore it
                    return(null);
                }

                return(AdjustmentRule.CreateAdjustmentRule(
                           startDate,
                           endDate,
                           TimeSpan.Zero,              // no daylight saving transition
                           TransitionTime.CreateFixedDateRule(DateTime.MinValue, 1, 1),
                           TransitionTime.CreateFixedDateRule(DateTime.MinValue.AddMilliseconds(1), 1, 1),
                           new TimeSpan(0, defaultBaseUtcOffset - timeZoneInformation.TZI.Bias, 0)));              // Bias delta is all what we need from this rule
            }

            //
            // Create an AdjustmentRule with TransitionTime objects
            //
            TransitionTime daylightTransitionStart;

            if (!TransitionTimeFromTimeZoneInformation(timeZoneInformation, out daylightTransitionStart, true /* start date */))
            {
                return(null);
            }

            TransitionTime daylightTransitionEnd;

            if (!TransitionTimeFromTimeZoneInformation(timeZoneInformation, out daylightTransitionEnd, false /* end date */))
            {
                return(null);
            }

            if (daylightTransitionStart.Equals(daylightTransitionEnd))
            {
                // this happens when the time zone does support DST but the OS has DST disabled
                return(null);
            }

            return(AdjustmentRule.CreateAdjustmentRule(
                       startDate,
                       endDate,
                       new TimeSpan(0, -timeZoneInformation.TZI.DaylightBias, 0),
                       (TransitionTime)daylightTransitionStart,
                       (TransitionTime)daylightTransitionEnd,
                       new TimeSpan(0, defaultBaseUtcOffset - timeZoneInformation.TZI.Bias, 0)));
        }
예제 #20
0
        public override void StartKinetic(VisualPayload payload, Func <float, float> translateTimeToEffectProportion)
        {
            var labelVis = payload.VisualData.Bound.GetComponent <LabelVisualizer>();

            var startValue            = StartValue.GetFirstValue(payload.Data);
            var endValue              = EndValue.GetFirstValue(payload.Data);
            var transitionTimeInverse = 1f / TransitionTime.GetFirstValue(payload.Data);;
            var formatString          = FormatString.GetFirstValue(payload.Data);
            var startTime             = Time.time;

            var bound = payload.VisualData.Bound.CreateDependingBound("Lerp Value");

            bound.transform.parent = payload.VisualData.Bound.transform.parent;
            payload.VisualData.Bound.transform.parent = bound.transform;

            var valueSatellite =
                bound.gameObject.AddComponent <SetLabelSatellite>();

            valueSatellite.LabelVis = labelVis;

            var newPayload = new VisualPayload(payload.Data, new VisualDescription(bound));


            valueSatellite.UpdateFunc = (label) =>
            {
                float proportion = (Time.time - startTime) * transitionTimeInverse;

                if (proportion >= 1)
                {
                    label.Text = string.Format(formatString, endValue);

                    valueSatellite.Cleanup();
                    return;
                }

                proportion = translateTimeToEffectProportion(proportion);

                var currentValue = Mathf.Lerp(startValue, endValue, proportion);

                label.Text = string.Format(formatString, currentValue);
            };

            valueSatellite.CleanupFunc = (label) =>
            {
                JobManager.Instance.StartJob(
                    Finished.Transmit(newPayload), jobName: "Kinetic Finished", startImmediately: true,
                    maxExecutionsPerFrame: 1);
            };

            //throw new NotImplementedException();
        }
예제 #21
0
        public void SaveXml(System.Xml.XmlWriter Writer, ConformPathHandler pathRewrite)
        {
            Writer.WriteStartElement("style");
            Writer.WriteAttributeString("name", Name);
            Writer.WriteAttributeString("transparent", BackgroundTransparent.ToString());
            Writer.WriteAttributeString("backColour", BackgroundColour.ToArgb().ToString());
            Writer.WriteAttributeString("backImage", BackgroundImage);
            Writer.WriteAttributeString("transitionTime", TransitionTime.ToString());

            SaveTextItem(Writer, PassageTitle, "passageTitle");
            SaveTextItem(Writer, MainText, "mainText");
            SaveTextItem(Writer, CopyRight, "copyrightText");

            Writer.WriteEndElement();
        }
예제 #22
0
        private static DateTime TransitionPoint(TransitionTime transition, int year)
        {
            if (transition.IsFixedDateRule)
            {
                return(new DateTime(year, transition.Month, transition.Day) + transition.TimeOfDay.TimeOfDay);
            }
            DayOfWeek dayOfWeek = new DateTime(year, transition.Month, 1).DayOfWeek;
            int       num       = 1 + (transition.Week - 1) * 7 + (transition.DayOfWeek - dayOfWeek) % 7;

            if (num > DateTime.DaysInMonth(year, transition.Month))
            {
                num -= 7;
            }
            return(new DateTime(year, transition.Month, num) + transition.TimeOfDay.TimeOfDay);
        }
예제 #23
0
 public static AdjustmentRule CreateAdjustmentRule(
     DateTime dateStart,
     DateTime dateEnd,
     TimeSpan daylightDelta,
     TransitionTime daylightTransitionStart,
     TransitionTime daylightTransitionEnd)
 {
     return(new AdjustmentRule(
                dateStart,
                dateEnd,
                daylightDelta,
                daylightTransitionStart,
                daylightTransitionEnd,
                baseUtcOffsetDelta: TimeSpan.Zero,
                noDaylightTransitions: false));
 }
예제 #24
0
        private static DateTime TransitionPoint(TransitionTime transition, int year)
        {
            if (transition.IsFixedDateRule)
            {
                return(new DateTime(year, transition.Month, transition.Day) + transition.TimeOfDay.TimeOfDay);
            }

            DayOfWeek first = (new DateTime(year, transition.Month, 1)).DayOfWeek;
            int       day   = 1 + (transition.Week - 1) * 7 + (transition.DayOfWeek - first) % 7;

            if (day > DateTime.DaysInMonth(year, transition.Month))
            {
                day -= 7;
            }
            return(new DateTime(year, transition.Month, day) + transition.TimeOfDay.TimeOfDay);
        }
예제 #25
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (Id != null)
         {
             hashCode = hashCode * 59 + Id.GetHashCode();
         }
         if (ProcessId != null)
         {
             hashCode = hashCode * 59 + ProcessId.GetHashCode();
         }
         if (IdentityId != null)
         {
             hashCode = hashCode * 59 + IdentityId.GetHashCode();
         }
         if (AllowedToEmployeeNames != null)
         {
             hashCode = hashCode * 59 + AllowedToEmployeeNames.GetHashCode();
         }
         if (TransitionTime != null)
         {
             hashCode = hashCode * 59 + TransitionTime.GetHashCode();
         }
         if (Order != null)
         {
             hashCode = hashCode * 59 + Order.GetHashCode();
         }
         if (InitialState != null)
         {
             hashCode = hashCode * 59 + InitialState.GetHashCode();
         }
         if (DestinationState != null)
         {
             hashCode = hashCode * 59 + DestinationState.GetHashCode();
         }
         if (Command != null)
         {
             hashCode = hashCode * 59 + Command.GetHashCode();
         }
         return(hashCode);
     }
 }
        public override void StartKinetic(VisualPayload payload, Func <float, float> translateTime)
        {
            var startVector           = StartPosition.GetFirstValue(payload.Data);
            var endVector             = EndPosition.GetFirstValue(payload.Data);
            var startTime             = TransitionTime.GetFirstValue(payload.Data);
            var transitionTimeInverse = 1f / (TransitionDuration.GetFirstValue(payload.Data));

            var bound = payload.VisualData.Bound.CreateDependingBound("Lerp Position");

            bound.transform.parent = payload.VisualData.Bound.transform.parent;

            payload.VisualData.Bound.transform.parent = bound.transform;

            var movementSatellite =
                bound.gameObject.AddComponent <BoundMovementSatellite>();

            var newPayload = new VisualPayload(payload.Data, new VisualDescription(bound));

            movementSatellite.MovementFunc = (trans) =>
            {
                float proportion = (Time.time - startTime) * transitionTimeInverse;

                if (proportion >= 1f)
                {
                    trans.position = endVector;

                    movementSatellite.Cleanup();
                    return;
                }

                proportion = translateTime(proportion);

                trans.position = Vector3.Lerp(startVector, endVector, proportion);
            };

            movementSatellite.CleanupFunc = (trans) =>
            {
                JobManager.Instance.StartJob(
                    Finished.Transmit(newPayload), jobName: "Kinetic Finished", startImmediately: true, maxExecutionsPerFrame: 1);
            };


            // execute first step immediately to set initial position
            movementSatellite.MovementFunc(movementSatellite.transform);
        }
예제 #27
0
    IEnumerator flickoroutine()
    {
        while (true)
        {
            l.color = OnColor;
            yield return(new WaitForSeconds(OnTime.Value()));

            float timer = 0, time = TransitionTime.Value();
            while (timer < time)
            {
                l.color = Color.Lerp(OnColor, OffColor, timer / time);
                timer  += Time.deltaTime;
                yield return(null);
            }

            yield return(new WaitForSeconds(OffTime.Value()));
        }
    }
예제 #28
0
 internal static AdjustmentRule CreateAdjustmentRule(
     DateTime dateStart,
     DateTime dateEnd,
     TimeSpan daylightDelta,
     TransitionTime daylightTransitionStart,
     TransitionTime daylightTransitionEnd,
     TimeSpan baseUtcOffsetDelta,
     bool noDaylightTransitions)
 {
     return(new AdjustmentRule(
                dateStart,
                dateEnd,
                daylightDelta,
                daylightTransitionStart,
                daylightTransitionEnd,
                baseUtcOffsetDelta,
                noDaylightTransitions));
 }
예제 #29
0
            private AdjustmentRule(
                DateTime dateStart,
                DateTime dateEnd,
                TimeSpan daylightDelta,
                TransitionTime daylightTransitionStart,
                TransitionTime daylightTransitionEnd,
                TimeSpan baseUtcOffsetDelta,
                bool noDaylightTransitions)
            {
                ValidateAdjustmentRule(dateStart, dateEnd, daylightDelta,
                                       daylightTransitionStart, daylightTransitionEnd, noDaylightTransitions);

                _dateStart               = dateStart;
                _dateEnd                 = dateEnd;
                _daylightDelta           = daylightDelta;
                _daylightTransitionStart = daylightTransitionStart;
                _daylightTransitionEnd   = daylightTransitionEnd;
                _baseUtcOffsetDelta      = baseUtcOffsetDelta;
                _noDaylightTransitions   = noDaylightTransitions;
            }
        /// <summary>
        /// Creates a time zone transition based on the specified transition time.
        /// </summary>
        /// <param name="timeZoneDefinition">The time zone definition that will own the transition.</param>
        /// <param name="targetPeriod">The period the transition will target.</param>
        /// <param name="transitionTime">The transition time to initialize from.</param>
        /// <returns>A TimeZoneTransition.</returns>
        internal static TimeZoneTransition CreateTimeZoneTransition(
            TimeZoneDefinition timeZoneDefinition,
            TimeZonePeriod targetPeriod,
            TransitionTime transitionTime)
        {
            TimeZoneTransition transition;

            if (transitionTime.IsFixedDateRule)
            {
                transition = new AbsoluteDayOfMonthTransition(timeZoneDefinition, targetPeriod);
            }
            else
            {
                transition = new RelativeDayOfMonthTransition(timeZoneDefinition, targetPeriod);
            }

            transition.InitializeFromTransitionTime(transitionTime);

            return(transition);
        }
예제 #31
0
		private static DateTime TransitionPoint (TransitionTime transition, int year)
		{
			if (transition.IsFixedDateRule)
				return new DateTime (year, transition.Month, transition.Day) + transition.TimeOfDay.TimeOfDay;

			DayOfWeek first = (new DateTime (year, transition.Month, 1)).DayOfWeek;
			int day = 1 + (transition.Week - 1) * 7 + (transition.DayOfWeek - first + 7) % 7;
			if (day >  DateTime.DaysInMonth (year, transition.Month))
				day -= 7;
			if (day < 1)
				day += 7;
			return new DateTime (year, transition.Month, day) + transition.TimeOfDay.TimeOfDay;
		}
예제 #32
0
        //
        // TransitionTimeFromTimeZoneInformation -
        //
        // Converts a REGISTRY_TIME_ZONE_INFORMATION (REG_TZI_FORMAT struct) to a TransitionTime
        //
        // * when the argument 'readStart' is true the corresponding daylightTransitionTimeStart field is read
        // * when the argument 'readStart' is false the corresponding dayightTransitionTimeEnd field is read
        //
        private static bool TransitionTimeFromTimeZoneInformation(REGISTRY_TIME_ZONE_INFORMATION timeZoneInformation, out TransitionTime transitionTime, bool readStartDate)
        {
            //
            // SYSTEMTIME - 
            //
            // If the time zone does not support daylight saving time or if the caller needs
            // to disable daylight saving time, the wMonth member in the SYSTEMTIME structure
            // must be zero. If this date is specified, the DaylightDate value in the 
            // TIME_ZONE_INFORMATION structure must also be specified. Otherwise, the system 
            // assumes the time zone data is invalid and no changes will be applied.
            //
            bool supportsDst = (timeZoneInformation.StandardDate.wMonth != 0);

            if (!supportsDst)
            {
                transitionTime = default(TransitionTime);
                return false;
            }

            //
            // SYSTEMTIME -
            //
            // * FixedDateRule -
            //   If the Year member is not zero, the transition date is absolute; it will only occur one time
            //
            // * FloatingDateRule -
            //   To select the correct day in the month, set the Year member to zero, the Hour and Minute 
            //   members to the transition time, the DayOfWeek member to the appropriate weekday, and the
            //   Day member to indicate the occurence of the day of the week within the month (first through fifth).
            //
            //   Using this notation, specify the 2:00a.m. on the first Sunday in April as follows: 
            //   Hour      = 2, 
            //   Month     = 4,
            //   DayOfWeek = 0,
            //   Day       = 1.
            //
            //   Specify 2:00a.m. on the last Thursday in October as follows:
            //   Hour      = 2,
            //   Month     = 10,
            //   DayOfWeek = 4,
            //   Day       = 5.
            //
            if (readStartDate)
            {
                //
                // read the "daylightTransitionStart"
                //
                if (timeZoneInformation.DaylightDate.wYear == 0)
                {
                    transitionTime = TransitionTime.CreateFloatingDateRule(
                                     new DateTime(1,    /* year  */
                                                  1,    /* month */
                                                  1,    /* day   */
                                                  timeZoneInformation.DaylightDate.wHour,
                                                  timeZoneInformation.DaylightDate.wMinute,
                                                  timeZoneInformation.DaylightDate.wSecond,
                                                  timeZoneInformation.DaylightDate.wMilliseconds),
                                     timeZoneInformation.DaylightDate.wMonth,
                                     timeZoneInformation.DaylightDate.wDay,   /* Week 1-5 */
                                     (DayOfWeek)timeZoneInformation.DaylightDate.wDayOfWeek);
                }
                else
                {
                    transitionTime = TransitionTime.CreateFixedDateRule(
                                     new DateTime(1,    /* year  */
                                                  1,    /* month */
                                                  1,    /* day   */
                                                  timeZoneInformation.DaylightDate.wHour,
                                                  timeZoneInformation.DaylightDate.wMinute,
                                                  timeZoneInformation.DaylightDate.wSecond,
                                                  timeZoneInformation.DaylightDate.wMilliseconds),
                                     timeZoneInformation.DaylightDate.wMonth,
                                     timeZoneInformation.DaylightDate.wDay);
                }
            }
            else
            {
                //
                // read the "daylightTransitionEnd"
                //
                if (timeZoneInformation.StandardDate.wYear == 0)
                {
                    transitionTime = TransitionTime.CreateFloatingDateRule(
                                     new DateTime(1,    /* year  */
                                                  1,    /* month */
                                                  1,    /* day   */
                                                  timeZoneInformation.StandardDate.wHour,
                                                  timeZoneInformation.StandardDate.wMinute,
                                                  timeZoneInformation.StandardDate.wSecond,
                                                  timeZoneInformation.StandardDate.wMilliseconds),
                                     timeZoneInformation.StandardDate.wMonth,
                                     timeZoneInformation.StandardDate.wDay,   /* Week 1-5 */
                                     (DayOfWeek)timeZoneInformation.StandardDate.wDayOfWeek);
                }
                else
                {
                    transitionTime = TransitionTime.CreateFixedDateRule(
                                     new DateTime(1,    /* year  */
                                                  1,    /* month */
                                                  1,    /* day   */
                                                  timeZoneInformation.StandardDate.wHour,
                                                  timeZoneInformation.StandardDate.wMinute,
                                                  timeZoneInformation.StandardDate.wSecond,
                                                  timeZoneInformation.StandardDate.wMilliseconds),
                                     timeZoneInformation.StandardDate.wMonth,
                                     timeZoneInformation.StandardDate.wDay);
                }
            }

            return true;
        }