Пример #1
0
        public Iso8601Time(int hour, int minute, int second, double fractionalSecond, Iso8601TimeZone timeZone)
        {
            Check.Require(ValidHour(hour, minute, second) && ValidMinute(minute) && ValidSecond(second) &&
                          ValidFractionalSecond(fractionalSecond));

            this.hour             = hour;
            this.minute           = minute;
            this.second           = second;
            this.fractionalSecond = fractionalSecond;
            this.timezone         = timeZone;
        }
Пример #2
0
        public DvTime(int hour, int minute, int second, double fractionalSecond,
                      int timeZoneSign, int timeZoneHour, int timeZoneMinute)
        {
            AssumedTypes.Iso8601TimeZone timeZone =
                new OpenEhr.AssumedTypes.Iso8601TimeZone
                    (timeZoneSign, timeZoneHour, timeZoneMinute);

            this.isoTime = new OpenEhr.AssumedTypes.Iso8601Time
                               (hour, minute, second, fractionalSecond, timeZone);

            this.CheckInvariants();
        }
Пример #3
0
        private void ParseTime(string timeString)
        {
            Check.Require(ValidIso8601Time(timeString), "The time string (" +
                          timeString + ") must be a valid ISO 8601 time.");

            //Regex rg = new Regex(timePattern);
            //Match thisMatch = rg.Match(timeString);
            Match thisMatch = Regex.Match(timeString, timePattern, RegexOptions.Compiled | RegexOptions.Singleline);

            GroupCollection gCollection = thisMatch.Groups;

            // assign values
            // hour
            string hString = gCollection[hourCaptureName].Value;

            Check.Require(!string.IsNullOrEmpty(hString), "Hour value must not be null or empty");
            this.hour = int.Parse(hString);

            // minutes
            string mString = gCollection[minuteCaptureName].Value;

            if (!string.IsNullOrEmpty(mString))
            {
                this.minute = int.Parse(mString);
                // seconds
                string sString = gCollection[secondCaptureName].Value;
                if (!string.IsNullOrEmpty(sString))
                {
                    this.second = int.Parse(sString);
                    // fraction seconds
                    string fsString = gCollection[decimalCaptureName].Value;
                    if (!string.IsNullOrEmpty(fsString))
                    {
                        if (fsString.IndexOf(",") >= 0)
                        {
                            this.isDecimalComma   = true;
                            this.fractionalSecond = double.Parse(fsString.Replace(',', '.'));
                        }
                        else if (fsString.IndexOf(".") >= 0)
                        {
                            this.isDecimalComma   = false;
                            this.fractionalSecond = double.Parse(fsString);
                        }
                    }
                }
            }
            if (timeString.IndexOf(":") >= 0)
            {
                this.isExtended = true;
            }
            else
            {
                this.isExtended = false;
            }

            // time zone
            string tZoneString = gCollection[iso8601TZoneCapturedName].Value;

            if (!string.IsNullOrEmpty(tZoneString))
            {
                this.timezone = new Iso8601TimeZone(tZoneString);
            }
        }
Пример #4
0
        public Iso8601Time(int hour, int minute, int second, double fractionalSecond, Iso8601TimeZone timeZone)
        {
            Check.Require(ValidHour(hour, minute, second) && ValidMinute(minute) && ValidSecond(second) &&
               ValidFractionalSecond(fractionalSecond));

            this.hour = hour;
            this.minute = minute;
            this.second = second;
            this.fractionalSecond = fractionalSecond;
            this.timezone = timeZone;
        }
Пример #5
0
        private void ParseTime(string timeString)
        {
            Check.Require(ValidIso8601Time(timeString), "The time string (" +
                timeString + ") must be a valid ISO 8601 time.");

            //Regex rg = new Regex(timePattern);
            //Match thisMatch = rg.Match(timeString);
            Match thisMatch = Regex.Match(timeString, timePattern, RegexOptions.Compiled | RegexOptions.Singleline);

            GroupCollection gCollection = thisMatch.Groups;

            // assign values
            // hour
            string hString = gCollection[hourCaptureName].Value;
            Check.Require(!string.IsNullOrEmpty(hString), "Hour value must not be null or empty");
            this.hour = int.Parse(hString);

            // minutes
            string mString = gCollection[minuteCaptureName].Value;
            if (!string.IsNullOrEmpty(mString))
            {
                this.minute = int.Parse(mString);
                // seconds
                string sString = gCollection[secondCaptureName].Value;
                if (!string.IsNullOrEmpty(sString))
                {
                    this.second = int.Parse(sString);
                    // fraction seconds
                    string fsString = gCollection[decimalCaptureName].Value;
                    if (!string.IsNullOrEmpty(fsString))
                    {
                        if (fsString.IndexOf(",") >= 0)
                        {
                            this.isDecimalComma = true;
                            this.fractionalSecond = double.Parse(fsString.Replace(',', '.'));
                        }
                        else if (fsString.IndexOf(".") >= 0)
                        {
                            this.isDecimalComma = false;
                            this.fractionalSecond = double.Parse(fsString);
                        }
                    }
                }
            }
            if (timeString.IndexOf(":")>=0)
                this.isExtended = true;
            else
                this.isExtended = false;

            // time zone
            string tZoneString = gCollection[iso8601TZoneCapturedName].Value;
            if (!string.IsNullOrEmpty(tZoneString))
                this.timezone = new Iso8601TimeZone(tZoneString);
        }
Пример #6
0
        public Iso8601DateTime(int year, int month, int day, int hour, int minute,
            int second, double fractionalSecond)
        {
            Check.Require(ValidYear(year) && ValidMonth(month) && ValidDay(year, month, day) &&
                ValidHour(hour, minute, second) && ValidMinute(minute) && ValidSecond(second) &&
                ValidFractionalSecond(fractionalSecond));

            this.year = year;
            this.month = month;
            this.day = day;
            this.hour = hour;
            this.minute = minute;
            this.second = second;
            this.fractionalSecond = fractionalSecond;

            this.timeZone = null;
        }
Пример #7
0
        public Iso8601DateTime(int year, int month, int day, int hour, int minute)
        {
            Check.Require(ValidYear(year) && ValidMonth(month) && ValidDay(year, month, day) &&
                ValidHour(hour, minute, second) && ValidMinute(minute));

            this.year = year;
            this.month = month;
            this.day = day;
            this.hour = hour;
            this.minute = minute;
            this.timeZone = null;
        }
Пример #8
0
        public Iso8601DateTime(int year, int month, int day, int hr)
        {
            Check.Require(ValidYear(year) && ValidMonth(month) && ValidDay(year, month, day) &&
               ValidHour(hr, 0, 0));

            this.year = year;
            this.month = month;
            this.day = day;
            this.hour = hr;

            this.timeZone = null;
        }
Пример #9
0
        public Iso8601DateTime(int year, int month, int day)
        {
            Check.Require(ValidYear(year), "The year (" + year + ") is not a valid ISO8601 year.");
            Check.Require(ValidMonth(month), "The month (" + month + ") is not a valid ISO8601 month.");
            Check.Require(ValidDay(year, month, day), "The month (" + day + ") is not a valid ISO8601 day.");

            this.year = year;
            this.month = month;
            this.day = day;
            this.timeZone = null;
        }
Пример #10
0
        public Iso8601DateTime(int year, int month)
        {
            Check.Require(ValidYear(year), "The year (" + year + ") is not a valid ISO8601 year.");
            Check.Require(ValidYear(month), "The month (" + month + ") is not a valid ISO8601 month.");

            this.year = year;
            this.month = month;
            this.timeZone = null;
        }
Пример #11
0
        public Iso8601DateTime(int year)
        {
            Check.Require(ValidYear(year), "The year (" + year + ") is not a valid ISO8601 year");

            this.year = year;

            this.timeZone = null;
        }
Пример #12
0
        public Iso8601DateTime(int year, int month, int day, int hour, int minute,
            int second, double fractionalSecond, int timeZoneSign, int timeZoneHour,
            int timeZoneMinute)
        {
            //%HYYKA%
            // CM: 16/09/08 need to allow partial dateTime
            //Check.Require(ValidYear(year) && ValidMonth(month) && ValidDay(year, month, day) &&
            //    ValidHour(hour, minute, second) && ValidMinute(minute) && ValidSecond(second) &&
            //    ValidFractionalSecond(fractionalSecond));
            Check.Require(ValidYear(year), "Must be a valid year: "+year);
            Check.Require(month<=0 || ValidMonth(month), "Must be a valid month: " + month);
            Check.Require(day <= 0 || ValidDay(year, month, day), "Must be a valid day: " + day);
            Check.Require(hour < 0 || ValidHour(hour, minute, second), "Must be a valid hour: " + hour);
            Check.Require(minute < 0 || ValidMinute(minute), "Must be a valid minute: " + minute);
            Check.Require(second < 0 || ValidSecond(second), "Must be a valid second: " + second);
            Check.Require(fractionalSecond < 0 || ValidFractionalSecond(fractionalSecond),
                "Must be a valid fractionalSection: " + fractionalSecond);

            Check.Require(timeZoneSign == 1 || timeZoneSign == -1);
            Check.Require(timeZoneHour >= 0 && timeZoneHour <= 12
                && timeZoneMinute >= 0 && timeZoneMinute <= 30);

            this.year = year;
            this.month = month;
            this.day = day;
            this.hour = hour;
            this.minute = minute;
            this.second = second;
            this.fractionalSecond = fractionalSecond;

            this.timeZone = new Iso8601TimeZone(timeZoneSign, timeZoneHour, timeZoneMinute);
        }
Пример #13
0
        /// <summary>
        /// Parse the date time string, extracts values from the string and assign these 
        /// values to the class properties.
        /// </summary>
        /// <param name="dateTime"></param>
        private void ParseDateTime(string dateTime)
        {
            // %HYYKA%
            // The date time must be a valid ISO 8601 date time.
            //Check.Require(ValidIso8601DateTime(dateTime),
            //    "Date time string(" + dateTime + ") must be a valid ISO 8601 date time.");

            Match thisMatch = dateTimeRegex.Match(dateTime);

            Check.Require(thisMatch.Success,
                "Date time string (" + dateTime + ") must be a valid ISO 8601 date time.");

            GroupCollection gCollection = thisMatch.Groups;

            // assign values
            // year
            string yString = gCollection[yearCaptureName].Value;
            this.year = int.Parse(yString);

            // month
            string monthString = gCollection[monthCaptureName].Value;
            if (!string.IsNullOrEmpty(monthString))
            {
                this.month = int.Parse(monthString);
            }

            // day
            string dString = gCollection[dayCaptureName].Value;
            if (!string.IsNullOrEmpty(dString))
            {
                this.day = int.Parse(dString);
            }

            // CM: 11/05/08 fixed a bug
            if (!string.IsNullOrEmpty(gCollection[monthCaptureName].Value))
            {
                string monthExtendedSign = dateTime.Substring(gCollection[monthCaptureName].Index - 1, 1);
                if (monthExtendedSign == "-")
                    this.isExtended = true;
                else
                    this.isExtended = false;
            }

            // time
            // assign values
            // hour
            string hString = gCollection[hourCaptureName].Value;
            if (!string.IsNullOrEmpty(hString))
            {
                this.hour = int.Parse(hString);

                // minutes
                string mString = gCollection[minuteCaptureName].Value;
                if (!string.IsNullOrEmpty(mString))
                {
                    this.minute = int.Parse(mString);
                    // seconds
                    string sString = gCollection[secondCaptureName].Value;
                    if (!string.IsNullOrEmpty(sString))
                    {
                        this.second = int.Parse(sString);
                        // fraction seconds
                        string fsString = gCollection[decimalCaptureName].Value;
                        if (!string.IsNullOrEmpty(fsString))
                        {
                            if (fsString.StartsWith(","))
                                this.isDecimalSignComma = true;
                            else
                                this.isDecimalSignComma = false;

                            if(fsString.Substring(0,1) != System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator)
                            {
                                fsString = string.Format("{0}{1}",System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator, fsString.Substring(1));
                            }

                            this.fractionalSecond = double.Parse(fsString);
                        }
                    }
                }

                // time zone
                string tZoneString = gCollection[iso8601TZoneCapturedName].Value;
                if (!string.IsNullOrEmpty(tZoneString))
                    this.timeZone = new Iso8601TimeZone(tZoneString);
            }
        }