コード例 #1
0
ファイル: DateTimeIndexSupport.cs プロジェクト: eug48/Pyro
        private static DateTimeIndex ParsePartialDateTimeOLD(PartialDateTime?PartialDateTimeType)
        {
            //2012-12-01T12:00:00+01:00
            //DateTimeOffset Low = PartialDateTimeType.Value.ToUniversalTime().ToLocalTime();
            //Get the localTime offset (+8:00 is Perth Australia, will always be relevent to the server location, Sydney +10:00 for PyroHealth.net)
            // var LocalTimeOffSet = DateTimeOffset.Now.Offset;
            //Convert to DateTimeOffset, which is done by caling ToUniversalTime(), yet this converts to UniversalTime
            // So we then set the timezone to the local timezone, which converts the time value to plus that timezone
            // So then subtract that timezone hours from the final result
            //Now we have the original timezone and correct time.
            //DateTimeOffset Low = PartialDateTimeType.Value.ToUniversalTime().ToOffset(LocalTimeOffSet).Subtract(LocalTimeOffSet);

            DateTimeOffset?Low = FhirDateTimeSupport.ConvertToDateTimeOffSetLow(PartialDateTimeType.Value.ToString());

            DateTimeOffset High = DateTimeOffset.MaxValue;

            if (Low.HasValue)
            {
                int DateCharCount = PartialDateTimeType.Value.ToString().Count();
                if (DateCharCount == 4)
                {
                    High = Low.Value.AddYears(1).AddMilliseconds(-1);
                }
                else if (DateCharCount == 7)
                {
                    High = Low.Value.AddMonths(1).AddMilliseconds(-1);
                }
                else if (DateCharCount == 10)
                {
                    High = Low.Value.AddDays(1).AddMilliseconds(-1);
                }
                else if (DateCharCount == 25)
                {
                    High = Low.Value.AddSeconds(1).AddMilliseconds(-1);
                }
                else if (DateCharCount == 27 || DateCharCount == 28 || DateCharCount == 29)
                {
                    High = Low.Value.AddMilliseconds(1);
                }
                else if (DateCharCount > 29)
                {
                    High = Low.Value.AddTicks(1);
                }
                return(new DateTimeIndex(Low.Value, High));
            }
            return(null);
        }
コード例 #2
0
        private static DateTimeIndex ParsePartialDateTime(PartialDateTime?PartialDateTimeType)
        {
            FhirDateTimeSupport FhirDateTimeSupport = new FhirDateTimeSupport(PartialDateTimeType.Value.ToString());

            if (FhirDateTimeSupport.IsValid)
            {
                DateTimeOffset?Low  = FhirDateTimeSupport.Value;
                DateTimeOffset High = DateTimeOffset.MaxValue;

                switch (FhirDateTimeSupport.Precision)
                {
                case FhirDateTimeSupport.DateTimePrecision.Year:
                    High = Low.Value.AddYears(1).AddMilliseconds(-1);
                    break;

                case FhirDateTimeSupport.DateTimePrecision.Month:
                    High = Low.Value.AddMonths(1).AddMilliseconds(-1);
                    break;

                case FhirDateTimeSupport.DateTimePrecision.Day:
                    High = Low.Value.AddDays(1).AddMilliseconds(-1);
                    break;

                case FhirDateTimeSupport.DateTimePrecision.HourMin:
                    High = Low.Value.AddSeconds(1).AddMilliseconds(-1);
                    break;

                case FhirDateTimeSupport.DateTimePrecision.Sec:
                    High = Low.Value.AddMilliseconds(999);
                    break;

                case FhirDateTimeSupport.DateTimePrecision.MilliSec:
                    High = Low.Value.AddMilliseconds(1).AddTicks(-1);
                    break;

                case FhirDateTimeSupport.DateTimePrecision.Tick:
                    High = Low.Value.AddTicks(1);
                    break;

                default:
                    break;
                }
                return(new DateTimeIndex(Low.Value, High));
            }
            return(null);
        }