]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/csharp/test/Apache.Arrow.Tests/TestDateAndTimeData.cs
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / csharp / test / Apache.Arrow.Tests / TestDateAndTimeData.cs
1 // Licensed to the Apache Software Foundation (ASF) under one or more
2 // contributor license agreements. See the NOTICE file distributed with
3 // this work for additional information regarding copyright ownership.
4 // The ASF licenses this file to You under the Apache License, Version 2.0
5 // (the "License"); you may not use this file except in compliance with
6 // the License. You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15
16 using System;
17 using System.Collections.Generic;
18 using System.Linq;
19
20 namespace Apache.Arrow.Tests
21 {
22 /// <summary>
23 /// The <see cref="TestDateAndTimeData"/> class holds example dates and times useful for testing.
24 /// </summary>
25 internal static class TestDateAndTimeData
26 {
27 private static readonly DateTime _earliestDate = new DateTime(1, 1, 1);
28 private static readonly DateTime _latestDate = new DateTime(9999, 12, 31);
29
30 private static readonly DateTime[] _exampleDates =
31 {
32 _earliestDate, new DateTime(1969, 12, 31), new DateTime(1970, 1, 1), new DateTime(1970, 1, 2),
33 new DateTime(1972, 6, 30), new DateTime(2015, 6, 30), new DateTime(2016, 12, 31), new DateTime(2020, 2, 29),
34 new DateTime(2020, 7, 1), _latestDate,
35 };
36
37 private static readonly TimeSpan[] _exampleTimes =
38 {
39 new TimeSpan(0, 0, 1), new TimeSpan(12, 0, 0), new TimeSpan(23, 59, 59),
40 };
41
42 private static readonly DateTimeKind[] _exampleKinds =
43 {
44 DateTimeKind.Local, DateTimeKind.Unspecified, DateTimeKind.Utc,
45 };
46
47 private static readonly TimeSpan[] _exampleOffsets =
48 {
49 TimeSpan.FromHours(-2),
50 TimeSpan.Zero,
51 TimeSpan.FromHours(2),
52 };
53
54 /// <summary>
55 /// Gets a collection of example dates (i.e. with a zero time component), of all different kinds.
56 /// </summary>
57 public static IEnumerable<DateTime> ExampleDates =>
58 from date in _exampleDates
59 from kind in _exampleKinds
60 select DateTime.SpecifyKind(date, kind);
61
62 /// <summary>
63 /// Gets a collection of example date/times, of all different kinds.
64 /// </summary>
65 public static IEnumerable<DateTime> ExampleDateTimes =>
66 from date in _exampleDates
67 from time in _exampleTimes
68 from kind in _exampleKinds
69 select DateTime.SpecifyKind(date.Add(time), kind);
70
71 /// <summary>
72 /// Gets a collection of example date time offsets.
73 /// </summary>
74 /// <returns></returns>
75 public static IEnumerable<DateTimeOffset> ExampleDateTimeOffsets =>
76 from date in _exampleDates
77 from time in _exampleTimes
78 from offset in _exampleOffsets
79 where !(date == _earliestDate && offset.Ticks > 0)
80 where !(date == _latestDate && offset.Ticks < 0)
81 select new DateTimeOffset(date.Add(time), offset);
82 }
83 }