Пример #1
0
        /// <summary>
        /// This is called by the containing form to apply a new time zone to the RDATE/EXDATE property date/time
        /// values in the control.
        /// </summary>
        /// <param name="oldTZ">The old time zone's ID</param>
        /// <param name="newTZ">The new time zone's ID</param>
        public void ApplyTimeZone(string oldTZ, string newTZ)
        {
            DateTimeInstance dti;
            int idx = 0;

            // This only applies to RDATE/EXDATE properties with a time
            foreach (RDateProperty rdt in rDates)
            {
                if (rdt.ValueLocation == ValLocValue.DateTime)
                {
                    if (oldTZ == null)
                    {
                        dti = VCalendar.LocalTimeToTimeZoneTime(rdt.TimeZoneDateTime, newTZ);
                    }
                    else
                    {
                        dti = VCalendar.TimeZoneToTimeZone(rdt.TimeZoneDateTime, oldTZ, newTZ);
                    }

                    rdt.TimeZoneDateTime = dti.StartDateTime;
                    lbRDates.Items[idx]  = dti.StartDateTime.ToString("G");
                }

                idx++;
            }
        }
Пример #2
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);
        }
Пример #3
0
        /// <summary>
        /// This is called by the containing form to apply a new time zone to the date/time values in the control
        /// </summary>
        /// <param name="oldTZ">The old time zone's ID</param>
        /// <param name="newTZ">The new time zone's ID</param>
        public void ApplyTimeZone(string oldTZ, string newTZ)
        {
            DateTimeInstance dti;

            if (oldTZ == null)
            {
                if (dtpStartDate.Checked)
                {
                    dti = VCalendar.LocalTimeToTimeZoneTime(dtpStartDate.Value, newTZ);
                    dtpStartDate.Value = dti.StartDateTime;
                }

                if (dtpEndDate.Checked)
                {
                    dti = VCalendar.LocalTimeToTimeZoneTime(dtpEndDate.Value, newTZ);
                    dtpEndDate.Value = dti.StartDateTime;
                }
            }
            else
            {
                if (dtpStartDate.Checked)
                {
                    dti = VCalendar.TimeZoneToTimeZone(dtpStartDate.Value, oldTZ, newTZ);
                    dtpStartDate.Value = dti.StartDateTime;
                }

                if (dtpEndDate.Checked)
                {
                    dti = VCalendar.TimeZoneToTimeZone(dtpEndDate.Value, oldTZ, newTZ);
                    dtpEndDate.Value = dti.StartDateTime;
                }
            }
        }
Пример #4
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);
                }
            }
        }
Пример #5
0
        /// <summary>
        /// This converts the date/time info to the specified time zone
        /// </summary>
        /// <param name="tzid">The time zone to which to convert this instance</param>
        /// <remarks>This converts the date time instance information from its current time zone identified by
        /// the <see cref="TimeZoneId"/> property to the specified time zone.  The time zone ID property will be
        /// set to the specified time zone after conversion.</remarks>
        public void ToTimeZone(string tzid)
        {
            DateTimeInstance dti, dtiEnd;

            // Already in the specified time zone?
            if (timeZoneID == tzid)
            {
                return;
            }

            // Convert from local time?
            if (timeZoneID == null)
            {
                dti    = VCalendar.LocalTimeToTimeZoneTime(startDate, tzid);
                dtiEnd = VCalendar.LocalTimeToTimeZoneTime(endDate, tzid);
            }
            else
            {
                dti    = VCalendar.TimeZoneToTimeZone(startDate, timeZoneID, tzid);
                dtiEnd = VCalendar.TimeZoneToTimeZone(endDate, timeZoneID, tzid);
            }

            timeZoneID  = dti.TimeZoneId;
            startDate   = dti.StartDateTime;
            startIsDST  = dti.StartIsDaylightSavingTime;
            startTZName = dti.StartTimeZoneName;
            endDate     = dtiEnd.EndDateTime;
            endIsDST    = dtiEnd.EndIsDaylightSavingTime;
            endTZName   = dtiEnd.EndTimeZoneName;
        }
Пример #6
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;
            }
        }
Пример #7
0
        /// <summary>
        /// This is called by the containing form to apply a new time zone to the date/time values in the control
        /// </summary>
        /// <param name="oldTZ">The old time zone's ID</param>
        /// <param name="newTZ">The new time zone's ID</param>
        public void ApplyTimeZone(string oldTZ, string newTZ)
        {
            DateTimeInstance dti;

            if (dtpTrigger.Checked)
            {
                if (oldTZ == null)
                {
                    dti = VCalendar.LocalTimeToTimeZoneTime(dtpTrigger.Value, newTZ);
                }
                else
                {
                    dti = VCalendar.TimeZoneToTimeZone(dtpTrigger.Value, oldTZ, newTZ);
                }

                dtpTrigger.Value = dti.StartDateTime;
                this.StoreChanges();
            }
        }
Пример #8
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);
        }
Пример #9
0
        /// <summary>
        /// This is used to apply the time zone selection to all date/time values in the dialog box
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event parameters</param>
        private void btnApplyTZ_Click(object sender, EventArgs e)
        {
            DateTimeInstance dti;
            string           sourceTZ, destTZ;

            if (cboTimeZone.SelectedIndex == timeZoneIdx)
            {
                MessageBox.Show("The time zone has not changed", "No Change", MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
                return;
            }

            if (MessageBox.Show(String.Format("Do you want to convert all times from the '{0}' time zone to " +
                                              "the '{1}' time zone?", cboTimeZone.Items[timeZoneIdx], cboTimeZone.Items[cboTimeZone.SelectedIndex]),
                                "Change Time Zone", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }

            // Get the time zone IDs
            if (timeZoneIdx == 0)
            {
                sourceTZ = null;
            }
            else
            {
                sourceTZ = (string)cboTimeZone.Items[timeZoneIdx];
            }

            destTZ = (string)cboTimeZone.Items[cboTimeZone.SelectedIndex];

            // Convert the times
            if (sourceTZ == null)
            {
                if (dtpStartDate.Checked)
                {
                    dti = VCalendar.LocalTimeToTimeZoneTime(dtpStartDate.Value, destTZ);
                    dtpStartDate.Value = dti.StartDateTime;
                }

                if (dtpEndDate.Checked)
                {
                    dti = VCalendar.LocalTimeToTimeZoneTime(dtpEndDate.Value, destTZ);
                    dtpEndDate.Value = dti.StartDateTime;
                }
            }
            else
            {
                if (dtpStartDate.Checked)
                {
                    dti = VCalendar.TimeZoneToTimeZone(dtpStartDate.Value, sourceTZ, destTZ);
                    dtpStartDate.Value = dti.StartDateTime;
                }

                if (dtpEndDate.Checked)
                {
                    dti = VCalendar.TimeZoneToTimeZone(dtpEndDate.Value, sourceTZ, destTZ);
                    dtpEndDate.Value = dti.StartDateTime;
                }
            }

            ucFreeBusy.ApplyTimeZone(sourceTZ, destTZ);

            timeZoneIdx = cboTimeZone.SelectedIndex;
        }