forked from novar0/TestApp
-
Notifications
You must be signed in to change notification settings - Fork 6
/
IDateTimeChanger.cs
118 lines (107 loc) · 4.08 KB
/
IDateTimeChanger.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System;
using System.Runtime.CompilerServices;
#pragma warning disable 8509
namespace TestApp
{
public interface IBool
{
}
public struct TrueType : IBool
{
}
public struct FalseType : IBool
{
}
public interface IDateTimeChanger
{
DateTime Change<TIsIncrementing>(DateTime t1) where TIsIncrementing : struct, IBool;
}
public struct YearsChanger : IDateTimeChanger
{
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public DateTime Change<TIsIncrementing>(DateTime t1) where TIsIncrementing : struct, IBool
{
var baseValue = new DateTime(t1.Year, 1, 1);
return default(TIsIncrementing) switch
{
TrueType _ => baseValue.AddYears(1),
FalseType _ => baseValue.AddMilliseconds(-1)
};
}
}
public struct MonthChanger : IDateTimeChanger
{
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public DateTime Change<TIsIncrementing>(DateTime t1) where TIsIncrementing : struct, IBool
{
var baseValue = new DateTime(t1.Year, t1.Month, 1);
return default(TIsIncrementing) switch
{
TrueType _ => baseValue.AddMonths(1),
FalseType _ => baseValue.AddMilliseconds(-1)
};
}
}
public struct DayChanger : IDateTimeChanger
{
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public DateTime Change<TIsIncrementing>(DateTime t1) where TIsIncrementing : struct, IBool
{
var baseValue = t1.Date;
return default(TIsIncrementing) switch
{
TrueType _ => baseValue.AddDays(1),
FalseType _ => baseValue.AddMilliseconds(-1)
};
}
}
public struct HourChanger : IDateTimeChanger
{
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public DateTime Change<TIsIncrementing>(DateTime t1) where TIsIncrementing : struct, IBool
{
var baseValue = new DateTime(t1.Year, t1.Month, t1.Day, t1.Hour, 0, 0);
return default(TIsIncrementing) switch
{
TrueType _ => baseValue.AddHours(1),
FalseType _ => baseValue.AddMilliseconds(-1)
};
}
}
public struct MinuteChanger : IDateTimeChanger
{
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public DateTime Change<TIsIncrementing>(DateTime t1) where TIsIncrementing : struct, IBool
{
var baseValue = new DateTime(t1.Year, t1.Month, t1.Day, t1.Hour, t1.Minute, 0);
return default(TIsIncrementing) switch
{
TrueType _ => baseValue.AddMinutes(1),
FalseType _ => baseValue.AddMilliseconds(-1)
};
}
}
public struct SecondChanger : IDateTimeChanger
{
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public DateTime Change<TIsIncrementing>(DateTime t1) where TIsIncrementing : struct, IBool
{
var baseValue = new DateTime(t1.Year, t1.Month, t1.Day, t1.Hour, t1.Minute, t1.Second);
return default(TIsIncrementing) switch
{
TrueType _ => baseValue.AddSeconds(1),
FalseType _ => baseValue.AddMilliseconds(-1)
};
}
}
public struct MillisecondChanger : IDateTimeChanger
{
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public DateTime Change<TIsIncrementing>(DateTime t1) where TIsIncrementing : struct, IBool =>
default(TIsIncrementing) switch
{
TrueType _ => t1.AddMilliseconds(1),
FalseType _ => t1.AddMilliseconds(-1)
};
}
}