public override T Get <T>(int item = -1) { if (typeof(T) == typeof(DicomDateRange)) { string[] vals = base.Get <string>(item).Split('-'); var range = new DicomDateRange(); if (vals.Length >= 2) { if (!String.IsNullOrEmpty(vals[0])) { range.Minimum = DateTime.ParseExact(vals[0], DateFormats, CultureInfo.CurrentCulture, DateTimeStyles.NoCurrentDateDefault); } if (!String.IsNullOrEmpty(vals[1])) { range.Maximum = DateTime.ParseExact(vals[1], DateFormats, CultureInfo.CurrentCulture, DateTimeStyles.NoCurrentDateDefault); } } else if (vals.Length == 1) { range.Minimum = DateTime.ParseExact(vals[0], DateFormats, CultureInfo.CurrentCulture, DateTimeStyles.NoCurrentDateDefault); range.Maximum = range.Minimum.AddDays(1).AddMilliseconds(-1); } return((T)(object)range); } if (_values == null) { string[] vals = base.Get <string[]>(); if (vals.Length == 1 && String.IsNullOrEmpty(vals[0])) { _values = new DateTime[0]; } else { _values = new DateTime[vals.Length]; for (int i = 0; i < vals.Length; i++) { _values[i] = DateTime.ParseExact(vals[i], DateFormats, CultureInfo.CurrentCulture, DateTimeStyles.NoCurrentDateDefault); } } } if (typeof(T) == typeof(DateTime) || typeof(T) == typeof(object)) { if (item < 0 || item >= Count) { throw new ArgumentOutOfRangeException("item", "Index is outside the range of available value items"); } return((T)((object)_values[item])); } if (typeof(T) == typeof(DateTime[]) || typeof(T) == typeof(object[])) { return((T)(object)_values); } return(base.Get <T>(item)); }
public void Add_TimeRange_GetDateRangeReturnsValidRange() { var dataset = new DicomDataset( new DicomUniqueIdentifier(DicomTag.SOPClassUID, DicomUID.SecondaryCaptureImageStorage), new DicomUniqueIdentifier(DicomTag.SOPInstanceUID, "1.2.3")); var expected = new DicomDateRange(new DateTime(1, 1, 1, 5, 10, 5), new DateTime(1, 1, 1, 19, 0, 20)); dataset.Add(DicomTag.AcquisitionTime, expected); var actual = dataset.Get <DicomDateRange>(DicomTag.AcquisitionTime); Assert.Equal(expected.Minimum, actual.Minimum); Assert.Equal(expected.Maximum, actual.Maximum); }
public DicomDateTime(DicomTag tag, DicomDateRange range) : base(tag, PrivateDateFormats, range) { }
protected DicomDateElement(DicomTag tag, string[] dateFormats, DicomDateRange range) : base(tag, DicomEncoding.Default, range.ToString(dateFormats[0])) { DateFormats = dateFormats; }