Example #1
0
 public TIME(TIME other)
 {
     HOUR   = other.HOUR;
     MINUTE = other.MINUTE;
     SECOND = other.SECOND;
     Form   = other.Form;
 }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TIME"/> struct with the specified hour,
 /// minute, second, time form and optionally the time zone identifier.
 /// </summary>
 /// <param name="hour">The digit representation of an hour.</param>
 /// <param name="minute">The digit representation of a minute.</param>
 /// <param name="second">The digit representation of a second.</param>
 /// <param name="form">The form in which the <see cref="TIME"/> instance is expressed.</param>
 /// <param name="tzid">The identifier that references the time zone.</param>
 public TIME(int hour, int minute, int second, TIME_FORM form = TIME_FORM.LOCAL)
 {
     HOUR   = hour;
     MINUTE = minute;
     SECOND = second;
     Form   = form;
 }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the the <see cref="TIMESTAMP"/> structure with a string value.
        /// </summary>
        /// <param name="value">
        /// The string representation of a <see cref="TIMESTAMP"/> to initialize the new <see
        /// cref="TIMESTAMP"/> instance with.
        /// </param>
        public TIMESTAMP(string value)
        {
            var fullyear = 1;
            var month    = 1;
            var mday     = 1;
            var hour     = 0;
            var minute   = 0;
            var second   = 0;
            var form     = TIME_FORM.LOCAL;

            const string       pattern = @"^((?<tzid>TZID=(\w+)?/(\w+)):)?(?<year>\d{4,})(?<month>\d{2})(?<day>\d{2})T(?<hour>\d{2})(?<min>\d{2})(?<sec>\d{2})(?<utc>Z)?$";
            const RegexOptions options = RegexOptions.IgnoreCase
                                         | RegexOptions.CultureInvariant
                                         | RegexOptions.ExplicitCapture
                                         | RegexOptions.Compiled;

            var regex = new Regex(pattern, options);

            foreach (Match match in regex.Matches(value))
            {
                if (match.Groups["year"].Success)
                {
                    fullyear = int.Parse(match.Groups["year"].Value);
                }
                if (match.Groups["month"].Success)
                {
                    month = int.Parse(match.Groups["month"].Value);
                }
                if (match.Groups["day"].Success)
                {
                    mday = int.Parse(match.Groups["day"].Value);
                }
                if (match.Groups["hour"].Success)
                {
                    hour = int.Parse(match.Groups["hour"].Value);
                }
                if (match.Groups["min"].Success)
                {
                    minute = int.Parse(match.Groups["min"].Value);
                }
                if (match.Groups["sec"].Success)
                {
                    second = int.Parse(match.Groups["sec"].Value);
                }
                if (match.Groups["utc"].Success)
                {
                    form = TIME_FORM.UTC;
                }
            }
            FULLYEAR = fullyear;
            MONTH    = month;
            MDAY     = mday;
            HOUR     = hour;
            MINUTE   = minute;
            SECOND   = second;
            Form     = form;
        }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DATE"/> structure with the year, month and day.
 /// </summary>
 /// <param name="fullyear">The 4-digit representation of a full year e.g. 2013.</param>
 /// <param name="month">The 2-digit representation of a month.</param>
 /// <param name="mday">The 2-digit representation of a day of the month.</param>
 /// <param name="hour">The digit representation of an hour.</param>
 /// <param name="minute">The digit representation of a minute.</param>
 /// <param name="second">The digit representation of a second.</param>
 /// <param name="form">The form in which the <see cref="TIMESTAMP"/> instance is expressed.</param>
 /// <param name="tzid">The identifier that references the time zone.</param>
 public TIMESTAMP(int fullyear, int month, int mday, int hour, int minute, int second, TIME_FORM form = TIME_FORM.LOCAL)
 {
     FULLYEAR = fullyear;
     MONTH    = month;
     MDAY     = mday;
     HOUR     = hour;
     MINUTE   = minute;
     SECOND   = second;
     Form     = form;
 }
Example #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TIME"/> struct with its equivalent string representation.
        /// </summary>
        /// <param name="value">The string representation of the <see cref="TIME"/> instance.</param>
        public TIME(string value)
        {
            var hour   = 0;
            var minute = 0;
            var second = 0;
            var form   = TIME_FORM.LOCAL;

            const string       pattern = @"^(?<hour>\d{1,2})(?<min>\d{1,2})(?<sec>\d{1,2})(?<utc>Z)?$";
            const RegexOptions options = RegexOptions.IgnoreCase
                                         | RegexOptions.CultureInvariant
                                         | RegexOptions.ExplicitCapture
                                         | RegexOptions.Compiled;

            var regex = new Regex(pattern, options);

            foreach (Match match in regex.Matches(value))
            {
                if (match.Groups["hour"].Success)
                {
                    hour = int.Parse(match.Groups["hour"].Value);
                }
                if (match.Groups["min"].Success)
                {
                    minute = int.Parse(match.Groups["min"].Value);
                }
                if (match.Groups["sec"].Success)
                {
                    second = int.Parse(match.Groups["sec"].Value);
                }
                if (match.Groups["utc"].Success)
                {
                    form = TIME_FORM.UTC;
                }
            }
            HOUR   = hour;
            MINUTE = minute;
            SECOND = second;
            Form   = form;
        }
Example #6
0
 /// <summary>
 /// Converts a <see cref="TIME_FORM"/> value to a <see cref="DateTimeKind"/> value.
 /// </summary>
 /// <param name="form">The form in which the time is expressed.</param>
 /// <returns>The <see cref="DateTimeKind"/> value that results from the conversion.</returns>
 public static DateTimeKind AsDateTimeKind(this TIME_FORM form)
 => form == TIME_FORM.UTC ? DateTimeKind.Utc : DateTimeKind.Local;