Exemplo n.º 1
0
        public void DisplayValue(System.TimeZone value)
        {
            EnsureInitialised();

            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            if (value == System.TimeZone.CurrentTimeZone)
            {
                radCurrent.Checked = true;
            }
            else
            {
                LinkMeType.TimeZone typeTz = value as LinkMeType.TimeZone;
                if (typeTz == null)
                {
                    throw new ArgumentException("Unsupported type of TimeZone object: "
                                                + value.GetType().FullName, "value");
                }

                if (typeTz.Equals(LinkMeType.TimeZone.UTC))
                {
                    radUtc.Checked = true;
                }
                else
                {
                    radSpecified.Checked = true;

                    bool found = false;
                    for (int index = 0; index < cboTimeZone.Items.Count; index++)
                    {
                        if (typeTz.StandardName == (string)cboTimeZone.Items[index])
                        {
                            found = true;
                            cboTimeZone.SelectedIndex = index;
                            break;
                        }
                    }

                    if (!found)
                    {
                        cboTimeZone.Items.Insert(0, value.StandardName);
                        cboTimeZone.SelectedIndex = 0;
                    }
                }
            }

            m_original = value;
            SetButtonEnabled(DialogResult.OK, false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns the XML representation of the object in a format similar to XSD dateTime
        /// (http://www.w3.org/TR/xmlschema-2/#dateTime). The returned value is always in UTC.
        /// If xsdCompliant is true then the returned value complies with XSD dateTime
        /// exactly, but time zone information is lost. Otherwise the name of the time zone
        /// is appended to the value, so it is not a valid XSD dateTime.
        /// </summary>
        internal string ToXml(bool xsdCompliant)
        {
            // The length of the output string not including the time zone, which is variable
            const int dateTimeLength = 30;

            // Get the time zone name, unless the user specified that the output should
            // comply with XSD dateTime format or the time zone is, in fact, UTC.

            string timeZoneName = null;
            int    outputLength = dateTimeLength;

            if (!xsdCompliant && !TimeZone.Equals(Type.TimeZone.UTC))
            {
                timeZoneName  = Type.TimeZone.ToString(TimeZone);
                outputLength += timeZoneName.Length + 1;
            }

            StringBuilder sb = new StringBuilder(outputLength);

            // Year
            sb.Append(DateTimeHelper.Digits(Universal.Year, 4));
            sb.Append('-');

            // Month
            sb.Append(DateTimeHelper.Digits(Universal.Month, 2));
            sb.Append('-');

            // Day
            sb.Append(DateTimeHelper.Digits(Universal.Day, 2));
            sb.Append('T');

            // Hour
            sb.Append(DateTimeHelper.Digits(Universal.Hour, 2));
            sb.Append(':');

            // Minute
            sb.Append(DateTimeHelper.Digits(Universal.Minute, 2));
            sb.Append(':');

            // Second
            sb.Append(DateTimeHelper.Digits(Second, 2));

            // Fractional seconds (if any) to a maximum of 9 decimal places
            long nanoseconds = (long)Nanosecond
                               + (long)Microsecond * DateTimeHelper.Microseconds2Nanoseconds
                               + (long)Millisecond * DateTimeHelper.Milliseconds2Nanoseconds;

            if (nanoseconds != 0)
            {
                sb.Append('.');
                string ns = nanoseconds.ToString();
                ns = ns.PadLeft(9, '0');
                sb.Append(ns.TrimEnd('0'));
            }

            sb.Append('Z');             // Specifies that this value is in UTC

            if (timeZoneName != null)
            {
                sb.Append(' ');
                sb.Append(timeZoneName);
            }

            return(sb.ToString());
        }