コード例 #1
0
ファイル: DateTimePeriod.cs プロジェクト: dixonalex/X12
        public static DateTimePeriod Parse(string s)
        {
            DateTimePeriod result = new DateTimePeriod();

            if (TryParse(s, out result) == false)
            {
                throw new FormatException(string.Format("Invalid DateTimePeriod format: {0}", s));
            }

            return(result);
        }
コード例 #2
0
 public void SetElement(int elementNumber, OopFactory.X12.Parsing.Model.Typed.DateTimePeriod value)
 {
     if (value == null)
     {
         SetElement(elementNumber, string.Empty);
     }
     else
     {
         SetElement(elementNumber, value.ToString());
     }
 }
コード例 #3
0
 public TypedElementHealthCareCodeInformation(Model.Segment _segment, int _elementNumber)
     : base(_segment, _elementNumber)
 {
     if (0 < SubElements.Count())
     {
         _1_CodeListQualifierCode = SubElements.ElementAt(0).ToEnumFromEDIFieldValue <CodeListQualifierCode>();
     }
     if (1 < SubElements.Count())
     {
         _2_IndustryCode = SubElements.ElementAt(1);
     }
     if (2 < SubElements.Count())
     {
         _3_DateTimePeriodFormatQualifierEnum = SubElements.ElementAt(2).ToEnumFromEDIFieldValue <DTPQualifier>();
     }
     if (3 < SubElements.Count())
     {
         _4_DateTimePeriod = new DateTimePeriod(SubElements.ElementAt(3));
     }
     if (4 < SubElements.Count())
     {
         _5_MonetaryAmount = Convert.ToDecimal(SubElements.ElementAt(4));
     }
     if (5 < SubElements.Count())
     {
         _6_Quantity = Convert.ToDecimal(SubElements.ElementAt(5));
     }
     if (6 < SubElements.Count())
     {
         _7_VersionIdentifier = SubElements.ElementAt(6);
     }
     if (7 < SubElements.Count())
     {
         _8_IndustryCode = SubElements.ElementAt(7);
     }
     if (8 < SubElements.Count())
     {
         _9_IndustryCode = SubElements.ElementAt(8);
     }
 }
コード例 #4
0
ファイル: DateTimePeriod.cs プロジェクト: dixonalex/X12
        public static bool TryParse(string s, out DateTimePeriod result)
        {
            result = new DateTimePeriod();

            if (string.IsNullOrWhiteSpace(s))
            {
                return(false);
            }

            int length = s.Length;

            // TM - hmm Time: 800
            if (length == 3)
            {
                TimeSpan ts;

                // TimeSpan TryParse in Mono seems broken. Manually do it.
                string sHours = s.Substring(0, 1);
                string sMin   = s.Substring(1);

                int iHours = 0;
                int iMin   = 0;

                if (!int.TryParse(sHours, out iHours))
                {
                    return(false);
                }

                if (!int.TryParse(sMin, out iMin))
                {
                    return(false);
                }

                try
                {
                    ts = new TimeSpan(iHours, iMin, 0);
                }
                catch (Exception)
                {
                    return(false);
                }

                result = new DateTimePeriod(ts);
                return(true);
            }

            // TM - hhmm Time: 0800
            if (length == 4)
            {
                TimeSpan ts;

                // TimeSpan TryParse in Mono seems broken. Manually do it.
                string sHours = s.Substring(0, 2);
                string sMin   = s.Substring(2);

                int iHours = 0;
                int iMin   = 0;

                if (!int.TryParse(sHours, out iHours))
                {
                    return(false);
                }

                if (!int.TryParse(sMin, out iMin))
                {
                    return(false);
                }

                try
                {
                    ts = new TimeSpan(iHours, iMin, 0);
                }
                catch (Exception)
                {
                    return(false);
                }

                result = new DateTimePeriod(ts);
                return(true);
            }

            // DT - yyyyMMddhhmm
            if (length == 12 && !s.Contains('-'))
            {
                TimeSpan ts;
                DateTime d;

                string sDate  = s.Substring(0, 8);
                string sHours = s.Substring(8, 2);
                string sMin   = s.Substring(10, 2);

                int iHours = 0;
                int iMin   = 0;

                if (!int.TryParse(sHours, out iHours))
                {
                    return(false);
                }

                if (!int.TryParse(sMin, out iMin))
                {
                    return(false);
                }

                try
                {
                    ts = new TimeSpan(iHours, iMin, 0);
                }
                catch (Exception)
                {
                    return(false);
                }

                if (!DateTime.TryParseExact(sDate, "yyyyMMdd", null, System.Globalization.DateTimeStyles.None, out d))
                {
                    return(false);
                }

                result = new DateTimePeriod(d, ts);
                return(true);
            }

            var dates = s.TrimEnd('-').TrimStart('-').Split('-');

            // D8 - yyyyMMDD
            if (dates.Length == 1)
            {
                DateTime d1;

                if (!DateTime.TryParseExact(dates[0], "yyyyMMdd", null, System.Globalization.DateTimeStyles.None, out d1))
                {
                    return(false);
                }

                result = new DateTimePeriod(d1);
                return(true);
            }

            // RD8 - yyyyMMDD-yyyyMMDD
            if (dates.Length == 2)
            {
                DateTime d1;
                DateTime d2;

                if (!DateTime.TryParseExact(dates[0], "yyyyMMdd", null, System.Globalization.DateTimeStyles.None, out d1))
                {
                    return(false);
                }

                if (!DateTime.TryParseExact(dates[1], "yyyyMMdd", null, System.Globalization.DateTimeStyles.None, out d2))
                {
                    return(false);
                }

                result = new DateTimePeriod(d1, d2);
                return(true);
            }

            return(false);
        }