예제 #1
0
        /// <summary>
        /// Convert the selected date/time to local time and back and to the selected time zone and back to test
        /// the time zone conversion code.
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        protected void btnApplySrc_Click(object sender, EventArgs e)
        {
            DateTime dt;

            VTimeZone vtzSource = VCalendar.TimeZones[cboSourceTimeZone.SelectedItem.Text];
            VTimeZone vtzDest   = VCalendar.TimeZones[cboDestTimeZone.SelectedItem.Text];

            // Show information for the selected time zones
            lblTimeZoneInfo.Text = String.Format("<strong>From Time Zone:</strong>\r\n\r\n" +
                                                 "{0}\r\n<strong>To Time Zone:</strong>\r\n\r\n{1}", vtzSource.ToString(), vtzDest.ToString());

            // Do the conversions.  Each is round tripped to make sure it gets the expected results.  Note that
            // there will be some anomalies when round tripping times that are near the standard time/DST shift
            // as these times are somewhat ambiguous and their meaning can vary depending on which side of the
            // shift you are on and the direction of the conversion.
            if (!DateTime.TryParse(txtSourceDate.Text, CultureInfo.CurrentCulture, DateTimeStyles.None, out dt))
            {
                lblLocalTime.Text         = "Invalid date/time format";
                lblLocalBackToSource.Text = lblDestTime.Text = lblDestBackToSource.Text = String.Empty;
                return;
            }

            DateTimeInstance dti = VCalendar.TimeZoneTimeToLocalTime(dt, vtzSource.TimeZoneId.Value);

            lblLocalTime.Text = String.Format("{0} {1}", dti.StartDateTime, dti.StartTimeZoneName);

            dti = VCalendar.LocalTimeToTimeZoneTime(dti.StartDateTime, vtzSource.TimeZoneId.Value);
            lblLocalBackToSource.Text = String.Format("{0} {1}", dti.StartDateTime, dti.StartTimeZoneName);

            dti = VCalendar.TimeZoneToTimeZone(dt, vtzSource.TimeZoneId.Value, vtzDest.TimeZoneId.Value);
            lblDestTime.Text = String.Format("{0} {1}", dti.StartDateTime, dti.StartTimeZoneName);

            dti = VCalendar.TimeZoneToTimeZone(dti.StartDateTime, vtzDest.TimeZoneId.Value, vtzSource.TimeZoneId.Value);
            lblDestBackToSource.Text = String.Format("{0} {1}", dti.StartDateTime, dti.StartTimeZoneName);
        }
예제 #2
0
        /// <summary>
        /// This is used to apply the selected time zone to all date/time objects in the component and convert
        /// them to the new time zone.
        /// </summary>
        /// <param name="vTimeZone">A <see cref="VTimeZone"/> object that will be used for all date/time objects
        /// in the component.</param>
        /// <remarks>When applied, all date/time values in the object will be converted to the new time zone</remarks>
        public override void ApplyTimeZone(VTimeZone vTimeZone)
        {
            if (rDates != null)
            {
                foreach (RDateProperty rdt in rDates)
                {
                    if (vTimeZone == null || rdt.TimeZoneId != vTimeZone.TimeZoneId.Value)
                    {
                        // If the time zone is null, just clear the time zone ID
                        if (vTimeZone == null)
                        {
                            rdt.TimeZoneId = null;
                        }
                        else
                        {
                            DateTimeInstance dti = VCalendar.TimeZoneToTimeZone(rdt.TimeZoneDateTime,
                                                                                rdt.TimeZoneId, vTimeZone.TimeZoneId.Value);

                            rdt.TimeZoneDateTime = dti.StartDateTime;
                            rdt.TimeZoneId       = vTimeZone.TimeZoneId.Value;
                        }
                    }
                }
            }

            if (exDates != null)
            {
                foreach (ExDateProperty edt in exDates)
                {
                    CalendarObject.ApplyPropertyTimeZone(edt, vTimeZone);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// This helper method can be used to apply a new time zone to the passed date/time property
        /// </summary>
        /// <param name="dateProp">The date/time property to check</param>
        /// <param name="vTimeZone">The new time zone component to use</param>
        /// <remarks>If the property's current time zone ID does not match the one in the new time zone, it is
        /// updated with the new ID and the date/time is adjusted to the new time zone.</remarks>
        protected static void ApplyPropertyTimeZone(BaseDateTimeProperty dateProp, VTimeZone vTimeZone)
        {
            if (dateProp != null && (vTimeZone == null || dateProp.TimeZoneId != vTimeZone.TimeZoneId.Value))
            {
                // If the time zone is null, just clear the time zone ID
                if (vTimeZone == null)
                {
                    dateProp.TimeZoneId = null;
                    return;
                }

                DateTimeInstance dti = VCalendar.TimeZoneToTimeZone(dateProp.TimeZoneDateTime, dateProp.TimeZoneId,
                                                                    vTimeZone.TimeZoneId.Value);

                dateProp.TimeZoneDateTime = dti.StartDateTime;
                dateProp.TimeZoneId       = vTimeZone.TimeZoneId.Value;
            }
        }
예제 #4
0
        /// <summary>
        /// Convert the selected date/time to local time and back and to the selected time zone and back to test
        /// the time zone conversion code.
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void UpdateTimes(object sender, EventArgs e)
        {
            // Wait until both have a value selected
            if (cboSourceTimeZone.SelectedIndex == -1 || cboDestTimeZone.SelectedIndex == -1)
            {
                return;
            }

            VTimeZone vtzSource = VCalendar.TimeZones[cboSourceTimeZone.SelectedIndex];
            VTimeZone vtzDest   = VCalendar.TimeZones[cboDestTimeZone.SelectedIndex];

            // Show information for the selected time zones
            txtTimeZoneInfo.Clear();
            txtTimeZoneInfo.AppendText("From Time Zone:\r\n");
            txtTimeZoneInfo.AppendText(vtzSource.ToString());
            txtTimeZoneInfo.AppendText("\r\n");
            txtTimeZoneInfo.AppendText("To Time Zone:\r\n");
            txtTimeZoneInfo.AppendText(vtzDest.ToString());

            // Do the conversions.  Each is round tripped to make sure it gets the expected results.  Note that
            // there will be some anomalies when round tripping times that are near the standard time/DST shift
            // as these times are somewhat ambiguous and their meaning can vary depending on which side of the
            // shift you are on and the direction of the conversion.
            DateTime dt = dtpSourceDate.Value;

            DateTimeInstance dti = VCalendar.TimeZoneTimeToLocalTime(dt, vtzSource.TimeZoneId.Value);

            lblLocalTime.Text = String.Format("{0} {1}", dti.StartDateTime, dti.StartTimeZoneName);

            dti = VCalendar.LocalTimeToTimeZoneTime(dti.StartDateTime, vtzSource.TimeZoneId.Value);
            lblLocalBackToSource.Text = String.Format("{0} {1}", dti.StartDateTime, dti.StartTimeZoneName);

            dti = VCalendar.TimeZoneToTimeZone(dt, vtzSource.TimeZoneId.Value, vtzDest.TimeZoneId.Value);
            lblDestTime.Text = String.Format("{0} {1}", dti.StartDateTime, dti.StartTimeZoneName);

            dti = VCalendar.TimeZoneToTimeZone(dti.StartDateTime, vtzDest.TimeZoneId.Value, vtzSource.TimeZoneId.Value);
            lblDestBackToSource.Text = String.Format("{0} {1}", dti.StartDateTime, dti.StartTimeZoneName);
        }
예제 #5
0
 /// <inheritdoc />
 public bool Equals(IDateTime value)
 {
     return(DateTimeInstance.Equals(value));
 }
예제 #6
0
        /// <summary>
        /// This method can be called to convert a date/time value from Universal Time (UTC) to the specified
        /// time zone time.
        /// </summary>
        /// <param name="convertDate">The universal (UTC) date/time value to convert to the time zone time.</param>
        /// <param name="timeZoneId">The time zone ID of a time zone definition in the <see cref="TimeZones"/>
        /// collection.</param>
        /// <returns>The date/time information in the time zone's time if the specified time zone is found in the
        /// collection or the unmodified date/time information if it cannot be found.</returns>
        /// <remarks>For this method, the end date/time information in the returned object is the same as the
        /// start date/time information and it has a zero length duration.</remarks>
        public static DateTimeInstance UtcToTimeZoneTime(DateTime convertDate, string timeZoneId)
        {
            ObservanceRule standardRule, daylightRule;
            DateTime standardDate, dstDate;
            TimeZoneNameProperty tzn;

            DateTimeInstance dti = new DateTimeInstance(convertDate);

            // We won't adjust values in year 1 or year 9999 as we could underflow or overflow the date/time
            // object.
            if(convertDate.Year == 1 || convertDate.Year == 9999)
                return dti;

            dti.TimeZoneId = timeZoneId;

            // Get the observance rules to use in the conversion
            FindRules(convertDate.ToLocalTime(), timeZoneId, false, out standardRule, out daylightRule,
                out standardDate, out dstDate);

            // If neither observance rule was found, use it as-is
            if(standardRule == null && daylightRule == null)
                return dti;

            // Keep the day part of the returned values but use the time value from the rule and shift it to UTC
            if(standardRule != null)
                standardDate = standardDate.Date.Add(standardRule.StartDateTime.DateTimeValue.TimeOfDay.Add(
                    standardRule.OffsetFrom.TimeSpanValue.Negate()));

            if(daylightRule != null)
                dstDate = dstDate.Date.Add(daylightRule.StartDateTime.DateTimeValue.TimeOfDay.Add(
                    daylightRule.OffsetFrom.TimeSpanValue.Negate()));

            // Standard rule only?
            if(standardRule != null && daylightRule == null)
            {
                // If on or after the standard time, use TZOFFSETTO.  Otherwise, assume it's DST and use
                // TZOFFSETFROM.
                if(convertDate >= standardDate)
                {
                    tzn = standardRule.TimeZoneNames[CultureInfo.CurrentCulture.Name];
                    dti.StartTimeZoneName = dti.EndTimeZoneName = (tzn == null) ? String.Empty : tzn.Value;
                    dti.StartDateTime = dti.EndDateTime = convertDate.Add(standardRule.OffsetTo.TimeSpanValue);
                }
                else
                {
                    // We don't have a time zone name for this case
                    dti.StartIsDaylightSavingTime = dti.EndIsDaylightSavingTime = true;
                    dti.StartDateTime = dti.EndDateTime = convertDate.Add(standardRule.OffsetFrom.TimeSpanValue);
                }

                return dti;
            }

            // Daylight rule only?
            if(daylightRule != null && standardRule == null)
            {
                // If on or after the daylight time, use TZOFFSETTO.  Otherwise, assume it's standard time and
                // use TZOFFSETFROM.
                if(convertDate >= dstDate)
                {
                    dti.StartIsDaylightSavingTime = dti.EndIsDaylightSavingTime = true;
                    tzn = daylightRule.TimeZoneNames[CultureInfo.CurrentCulture.Name];
                    dti.StartTimeZoneName = dti.EndTimeZoneName = (tzn == null) ? String.Empty : tzn.Value;
                    dti.StartDateTime = dti.EndDateTime = convertDate.Add(daylightRule.OffsetTo.TimeSpanValue);
                }
                else
                {
                    // We don't have a time zone name for this case
                    dti.StartDateTime = dti.EndDateTime = convertDate.Add(daylightRule.OffsetFrom.TimeSpanValue);
                }

                return dti;
            }

            // Got both, see if it's between them.  In the southern hemisphere, the dates are reversed so take
            // that into account.
            if(standardDate > dstDate)
            {
                // Northern hemisphere
                if(convertDate >= dstDate && convertDate < standardDate)
                {
                    dti.StartIsDaylightSavingTime = dti.EndIsDaylightSavingTime = true;
                    tzn = daylightRule.TimeZoneNames[CultureInfo.CurrentCulture.Name];
                    dti.StartTimeZoneName = dti.EndTimeZoneName = (tzn == null) ? String.Empty : tzn.Value;
                    dti.StartDateTime = dti.EndDateTime = convertDate.Add(daylightRule.OffsetTo.TimeSpanValue);
                }
                else
                {
                    tzn = standardRule.TimeZoneNames[CultureInfo.CurrentCulture.Name];
                    dti.StartTimeZoneName =  dti.EndTimeZoneName = (tzn == null) ? String.Empty : tzn.Value;
                    dti.StartDateTime = dti.EndDateTime = convertDate.Add(standardRule.OffsetTo.TimeSpanValue);
                }
            }
            else    // Southern hemisphere
                if(convertDate >= standardDate && convertDate < dstDate)
                {
                    tzn = standardRule.TimeZoneNames[CultureInfo.CurrentCulture.Name];
                    dti.StartTimeZoneName = dti.EndTimeZoneName = (tzn == null) ? String.Empty : tzn.Value;
                    dti.StartDateTime = dti.EndDateTime = convertDate.Add(standardRule.OffsetTo.TimeSpanValue);
                }
                else
                {
                    dti.StartIsDaylightSavingTime = dti.EndIsDaylightSavingTime = true;
                    tzn = daylightRule.TimeZoneNames[CultureInfo.CurrentCulture.Name];
                    dti.StartTimeZoneName = dti.EndTimeZoneName = (tzn == null) ? String.Empty : tzn.Value;
                    dti.StartDateTime = dti.EndDateTime = convertDate.Add(daylightRule.OffsetTo.TimeSpanValue);
                }

            return dti;
        }
예제 #7
0
 /// <inheritdoc />
 public IDateTime AddYears(int value)
 {
     return(new DateTimeWrap(DateTimeInstance.AddYears(value)));
 }
예제 #8
0
 /// <inheritdoc />
 public IDateTime ToUniversalTime()
 {
     return(new DateTimeWrap(DateTimeInstance.ToUniversalTime()));
 }
예제 #9
0
        /// <summary>
        /// This method can be called to convert a date/time value from one time zone time to the another time
        /// zone time.
        /// </summary>
        /// <param name="convertDate">The date/time in the source time zone to convert to the destination time
        /// zone</param>
        /// <param name="sourceId">The time zone ID of a time zone definition in the <see cref="TimeZones"/>
        /// collection that represents the date/time's current time zone.</param>
        /// <param name="destId">The time zone ID of a time zone definition in the <see cref="TimeZones"/>
        /// collection that represents the destination time zone.</param>
        /// <returns>The time zone date/time information in the destination time zone's time if the specified
        /// time zones are found in the collection or the unmodified date/time information if one or both cannot
        /// be found.</returns>
        /// <remarks>For this method, the end date/time information in the returned object is the same as the
        /// start date/time information and it has a zero length duration.</remarks>
        public static DateTimeInstance TimeZoneToTimeZone(DateTime convertDate, string sourceId, string destId)
        {
            DateTimeInstance dti;

            // If one or both is not found, return it as-is
            if(timeZones[sourceId] == null || timeZones[destId] == null)
                dti = new DateTimeInstance(convertDate);
            else
            {
                // Convert it from the source time zone to UTC and then from UTC to the destination time zone
                dti = VCalendar.UtcToTimeZoneTime(VCalendar.TimeZoneTimeToUtc(convertDate, sourceId), destId);
            }

            return dti;
        }
예제 #10
0
 /// <summary>
 /// Converts the value of the current IDateTimeWrap object to its equivalent string representation.
 /// </summary>
 /// <returns>A string representation of the value of the current IDateTimeWrap object.</returns>
 public override string ToString()
 {
     return(DateTimeInstance.ToString());
 }
예제 #11
0
 /// <inheritdoc />
 public string ToString(string format)
 {
     return(DateTimeInstance.ToString(format));
 }
예제 #12
0
 /// <inheritdoc />
 public override int GetHashCode()
 {
     return(DateTimeInstance.GetHashCode());
 }
예제 #13
0
 /// <inheritdoc />
 public TypeCode GetTypeCode()
 {
     return(DateTimeInstance.GetTypeCode());
 }
예제 #14
0
 /// <inheritdoc />
 public string[] GetDateTimeFormats(IFormatProvider provider)
 {
     return(DateTimeInstance.GetDateTimeFormats(provider));
 }
예제 #15
0
 /// <inheritdoc />
 public string[] GetDateTimeFormats(char format, IFormatProvider provider)
 {
     return(DateTimeInstance.GetDateTimeFormats(format, provider));
 }
예제 #16
0
 /// <inheritdoc />
 public string[] GetDateTimeFormats(char format)
 {
     return(DateTimeInstance.GetDateTimeFormats(format));
 }
예제 #17
0
 /// <inheritdoc />
 public string[] GetDateTimeFormats()
 {
     return(DateTimeInstance.GetDateTimeFormats());
 }
예제 #18
0
 /// <inheritdoc />
 public override bool Equals(object obj)
 {
     return(DateTimeInstance.Equals(obj));
 }
예제 #19
0
 /// <inheritdoc />
 public double ToOADate()
 {
     return(DateTimeInstance.ToOADate());
 }
예제 #20
0
 /// <inheritdoc />
 public bool IsDaylightSavingTime()
 {
     return(DateTimeInstance.IsDaylightSavingTime());
 }
예제 #21
0
 /// <inheritdoc />
 public string ToShortTimeString()
 {
     return(DateTimeInstance.ToShortTimeString());
 }
예제 #22
0
 /// <inheritdoc />
 public TimeSpan Subtract(IDateTime value)
 {
     return(DateTimeInstance.Subtract(value.DateTimeInstance));
 }
예제 #23
0
 /// <inheritdoc />
 public string ToString(IFormatProvider provider)
 {
     return(DateTimeInstance.ToString(provider));
 }
예제 #24
0
 /// <inheritdoc />
 public IDateTime Subtract(TimeSpan value)
 {
     return(new DateTimeWrap(DateTimeInstance.Subtract(value)));
 }
예제 #25
0
 /// <inheritdoc />
 public string ToString(string format, IFormatProvider provider)
 {
     return(DateTimeInstance.ToString(format, provider));
 }
예제 #26
0
 /// <inheritdoc />
 public long ToBinary()
 {
     return(DateTimeInstance.ToBinary());
 }
예제 #27
0
        /// <summary>
        /// This method can be called to convert a date/time value from the specified time zone time to local
        /// time.
        /// </summary>
        /// <param name="convertDate">The time zone date/time to convert to local time.</param>
        /// <param name="timeZoneId">The time zone ID of a time zone definition in the <see cref="TimeZones"/>
        /// collection.</param>
        /// <returns>The date/time information in local time if the specified time zone is found in the
        /// collection or the unmodified date/time information if it cannot be found.</returns>
        /// <remarks>For this method, the end date/time information in the returned object is the same as the
        /// start date/time information and it has a zero length duration.</remarks>
        public static DateTimeInstance TimeZoneTimeToLocalTime(DateTime convertDate, string timeZoneId)
        {
            ObservanceRule standardRule, daylightRule;
            DateTime standardDate, daylightDate;

            DateTimeInstance dti = new DateTimeInstance(convertDate);

            // We won't adjust values in year 1 or year 9999 as we could underflow or overflow the date/time
            // object.
            if(convertDate.Year == 1 || convertDate.Year == 9999)
                return dti;

            // Get the observance rules to use in the conversion
            FindRules(convertDate, timeZoneId, false, out standardRule, out daylightRule, out standardDate,
                out daylightDate);

            // If neither observance rule was found, use it as-is
            if(standardRule == null && daylightRule == null)
                return dti;

            // Standard rule only?
            if(standardRule != null && daylightRule == null)
            {
                // If on or after the standard time, use TZOFFSETTO.  Otherwise, assume it's DST and use
                // TZOFFSETFROM.
                if(convertDate >= standardDate)
                {
                    dti.StartDateTime = dti.EndDateTime = convertDate.Add(
                        standardRule.OffsetTo.TimeSpanValue.Negate()).ToLocalTime();
                }
                else
                    dti.StartDateTime = dti.EndDateTime = convertDate.Add(
                        standardRule.OffsetFrom.TimeSpanValue.Negate()).ToLocalTime();

                // Base the time zone name on the local time's DST setting
                if(TimeZone.CurrentTimeZone.IsDaylightSavingTime(dti.StartDateTime))
                {
                    dti.StartIsDaylightSavingTime = dti.EndIsDaylightSavingTime = true;
                    dti.StartTimeZoneName = dti.EndTimeZoneName = TimeZone.CurrentTimeZone.DaylightName;
                }
                else
                    dti.StartTimeZoneName = dti.EndTimeZoneName = TimeZone.CurrentTimeZone.StandardName;

                return dti;
            }

            // Daylight rule only?
            if(daylightRule != null && standardRule == null)
            {
                // If on or after the daylight time, use TZOFFSETTO.  Otherwise, assume it's standard time and
                // use TZOFFSETFROM.
                if(convertDate >= daylightDate)
                {
                    // If in the missing hour, bump it forward an hour
                    if(convertDate.Date == daylightDate.Date && convertDate.Hour == daylightDate.Hour)
                        convertDate = convertDate.AddHours(1);

                    dti.StartDateTime = dti.EndDateTime = convertDate.Add(
                        daylightRule.OffsetTo.TimeSpanValue.Negate()).ToLocalTime();
                }
                else
                    dti.StartDateTime = dti.EndDateTime = convertDate.Add(
                        daylightRule.OffsetFrom.TimeSpanValue.Negate()).ToLocalTime();

                // Base the time zone name on the local time's DST setting
                if(TimeZone.CurrentTimeZone.IsDaylightSavingTime(dti.StartDateTime))
                {
                    dti.StartIsDaylightSavingTime = dti.EndIsDaylightSavingTime = true;
                    dti.StartTimeZoneName = dti.EndTimeZoneName = TimeZone.CurrentTimeZone.DaylightName;
                }
                else
                    dti.StartTimeZoneName = dti.EndTimeZoneName = TimeZone.CurrentTimeZone.StandardName;

                return dti;
            }

            // Got both, see if it's between them.  In the southern hemisphere, the dates are reversed so take
            // that into account too.
            if(standardDate > daylightDate)
            {
                // Northern hemisphere
                if(convertDate >= daylightDate && convertDate < standardDate)
                {
                    // If in the missing hour, bump it forward an hour
                    if(convertDate.Date == daylightDate.Date && convertDate.Hour == daylightDate.Hour)
                        convertDate = convertDate.AddHours(1);

                    dti.StartDateTime = dti.EndDateTime = convertDate.Add(
                        daylightRule.OffsetTo.TimeSpanValue.Negate()).ToLocalTime();
                }
                else
                    dti.StartDateTime = dti.EndDateTime = convertDate.Add(
                        standardRule.OffsetTo.TimeSpanValue.Negate()).ToLocalTime();
            }
            else    // Southern hemisphere
                if(convertDate >= standardDate && convertDate < daylightDate)
                {
                    dti.StartDateTime = dti.EndDateTime = convertDate.Add(
                        standardRule.OffsetTo.TimeSpanValue.Negate()).ToLocalTime();
                }
                else
                {
                    // If in the missing hour, bump it forward an hour
                    if(convertDate.Date == daylightDate.Date && convertDate.Hour == daylightDate.Hour)
                        convertDate = convertDate.AddHours(1);

                    dti.StartDateTime = dti.EndDateTime = convertDate.Add(
                        daylightRule.OffsetTo.TimeSpanValue.Negate()).ToLocalTime();
                }

            // Base the time zone name on the local time's DST setting
            if(TimeZone.CurrentTimeZone.IsDaylightSavingTime(dti.StartDateTime))
            {
                dti.StartIsDaylightSavingTime = dti.EndIsDaylightSavingTime = true;
                dti.StartTimeZoneName = dti.EndTimeZoneName = TimeZone.CurrentTimeZone.DaylightName;
            }
            else
                dti.StartTimeZoneName = dti.EndTimeZoneName = TimeZone.CurrentTimeZone.StandardName;

            return dti;
        }
예제 #28
0
 /// <inheritdoc />
 public IDateTime AddTicks(long value)
 {
     return(new DateTimeWrap(DateTimeInstance.AddTicks(value)));
 }
예제 #29
0
        /// <summary>
        /// This method can be called to get daylight saving time and time zone name information for a specified
        /// date/time.
        /// </summary>
        /// <param name="infoDate">The time zone date/time for which to get information.</param>
        /// <param name="timeZoneId">The time zone ID of a time zone definition in the <see cref="TimeZones"/>
        /// collection.</param>
        /// <returns>The date/time information if the specified time zone is found in the collection or the
        /// unmodified date/time information if it cannot be found.</returns>
        /// <remarks>For this method, the end date/time information in the returned object is the same as the
        /// start date/time information and it has a zero length duration.</remarks>
        public static DateTimeInstance TimeZoneTimeInfo(DateTime infoDate, string timeZoneId)
        {
            ObservanceRule standardRule, daylightRule;
            DateTime standardDate, dstDate;
            TimeZoneNameProperty tzn;

            DateTimeInstance dti = new DateTimeInstance(infoDate);

            // We won't adjust values in year 1 or year 9999 as we could underflow or overflow the date/time
            // object.
            if(infoDate.Year == 1 || infoDate.Year == 9999)
                return dti;

            dti.TimeZoneId = timeZoneId;

            // Get the observance rules to use in the conversion
            FindRules(infoDate, timeZoneId, false, out standardRule, out daylightRule, out standardDate,
                out dstDate);

            // If neither observance rule was found, use it as-is
            if(standardRule == null && daylightRule == null)
                return dti;

            // Standard rule only?
            if(standardRule != null && daylightRule == null)
            {
                if(infoDate >= standardDate)
                {
                    tzn = standardRule.TimeZoneNames[CultureInfo.CurrentCulture.Name];
                    dti.StartTimeZoneName = dti.EndTimeZoneName = (tzn == null) ? String.Empty : tzn.Value;
                }
                else    // We don't have a time zone name for this case
                    dti.StartIsDaylightSavingTime = dti.EndIsDaylightSavingTime = true;

                return dti;
            }

            // Daylight rule only?
            if(daylightRule != null && standardRule == null)
            {
                // We don't have a time zone name if not DST
                if(infoDate >= dstDate)
                {
                    // If in the missing hour, bump it forward an hour
                    if(infoDate.Date == dstDate.Date && infoDate.Hour == dstDate.Hour)
                        dti.StartDateTime = dti.EndDateTime = infoDate.AddHours(1);

                    dti.StartIsDaylightSavingTime = dti.EndIsDaylightSavingTime = true;
                    tzn = daylightRule.TimeZoneNames[CultureInfo.CurrentCulture.Name];
                    dti.StartTimeZoneName = dti.EndTimeZoneName = (tzn == null) ? String.Empty : tzn.Value;
                }

                return dti;
            }

            // Got both, see if it's between them.  In the southern hemisphere, the dates are reversed so take
            // that into account.
            if(standardDate > dstDate)
            {
                // Northern hemisphere
                if(infoDate >= dstDate && infoDate < standardDate)
                {
                    // If in the missing hour, bump it forward an hour
                    if(infoDate.Date == dstDate.Date && infoDate.Hour == dstDate.Hour)
                        dti.StartDateTime = dti.EndDateTime = infoDate.AddHours(1);

                    dti.StartIsDaylightSavingTime = dti.EndIsDaylightSavingTime = true;
                    tzn = daylightRule.TimeZoneNames[CultureInfo.CurrentCulture.Name];
                    dti.StartTimeZoneName = dti.EndTimeZoneName = (tzn == null) ? String.Empty : tzn.Value;
                }
                else
                {
                    tzn = standardRule.TimeZoneNames[CultureInfo.CurrentCulture.Name];
                    dti.StartTimeZoneName =  dti.EndTimeZoneName = (tzn == null) ? String.Empty : tzn.Value;
                }
            }
            else    // Southern hemisphere
                if(infoDate >= standardDate && infoDate < dstDate)
                {
                    tzn = standardRule.TimeZoneNames[CultureInfo.CurrentCulture.Name];
                    dti.StartTimeZoneName = dti.EndTimeZoneName = (tzn == null) ? String.Empty : tzn.Value;
                }
                else
                {
                    // If in the missing hour, bump it forward an hour
                    if(infoDate.Date == dstDate.Date && infoDate.Hour == dstDate.Hour)
                        dti.StartDateTime = dti.EndDateTime = infoDate.AddHours(1);

                    dti.StartIsDaylightSavingTime = dti.EndIsDaylightSavingTime = true;
                    tzn = daylightRule.TimeZoneNames[CultureInfo.CurrentCulture.Name];
                    dti.StartTimeZoneName = dti.EndTimeZoneName = (tzn == null) ? String.Empty : tzn.Value;
                }

            return dti;
        }
예제 #30
0
 /// <inheritdoc />
 public IDateTime ToLocalTime()
 {
     return(new DateTimeWrap(DateTimeInstance.ToLocalTime()));
 }
예제 #31
0
 /// <inheritdoc />
 public int CompareTo(IDateTime value)
 {
     return(DateTimeInstance.CompareTo(value.DateTimeInstance));
 }
예제 #32
0
 /// <inheritdoc />
 public string ToLongTimeString()
 {
     return(DateTimeInstance.ToLongTimeString());
 }
예제 #33
0
 /// <inheritdoc />
 public long ToFileTimeUtc()
 {
     return(DateTimeInstance.ToFileTimeUtc());
 }
예제 #34
0
 /// <inheritdoc />
 public int CompareTo(object value)
 {
     return(DateTimeInstance.CompareTo(value));
 }