-
Notifications
You must be signed in to change notification settings - Fork 2
/
Module.Date.m
164 lines (116 loc) · 8.61 KB
/
Module.Date.m
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// Copyright (c) Microsoft Corporation. All rights reserved.
section Date;
shared Date.IsInPreviousDay = (dateTime) as nullable logical =>
Date.IsInPreviousNDays(dateTime, 1);
shared Date.IsInPreviousNDays = (dateTime, days as number) as nullable logical =>
Date.From(dateTime) >= Date.From(Date.AddDays(DateTime.FixedLocalNow(), -days)) and
Date.From(dateTime) < Date.From(DateTime.FixedLocalNow());
shared Date.IsInCurrentDay = (dateTime) as nullable logical =>
Date.From(dateTime) >= Date.From(DateTime.FixedLocalNow()) and
Date.From(dateTime) < Date.From(Date.AddDays(DateTime.FixedLocalNow(), 1));
shared Date.IsInNextDay = (dateTime) as nullable logical =>
Date.IsInNextNDays(dateTime, 1);
shared Date.IsInNextNDays = (dateTime, days as number) as nullable logical =>
Date.From(dateTime) >= Date.From(Date.AddDays(DateTime.FixedLocalNow(), 1)) and
Date.From(dateTime) < Date.From(Date.AddDays(DateTime.FixedLocalNow(), days + 1));
shared Date.IsInPreviousWeek = (dateTime) as nullable logical =>
Date.IsInPreviousNWeeks(dateTime, 1);
shared Date.IsInPreviousNWeeks = (dateTime, weeks as number) as nullable logical =>
Date.From(dateTime) >= Date.From(Date.StartOfWeek(Date.AddWeeks(DateTime.FixedLocalNow(), -weeks))) and
Date.From(dateTime) < Date.From(Date.StartOfWeek(DateTime.FixedLocalNow()));
shared Date.IsInCurrentWeek = (dateTime) as nullable logical =>
Date.From(dateTime) >= Date.From(Date.StartOfWeek(DateTime.FixedLocalNow())) and
Date.From(dateTime) < Date.From(Date.AddDays(Date.EndOfWeek(DateTime.FixedLocalNow()), 1));
shared Date.IsInNextWeek = (dateTime) as nullable logical =>
Date.IsInNextNWeeks(dateTime, 1);
shared Date.IsInNextNWeeks = (dateTime, weeks as number) as nullable logical =>
Date.From(dateTime) >= Date.From(Date.AddDays(Date.EndOfWeek(DateTime.FixedLocalNow()), 1)) and
Date.From(dateTime) < Date.From(Date.AddDays(Date.EndOfWeek(Date.AddWeeks(DateTime.FixedLocalNow(), weeks)), 1));
shared Date.IsInPreviousMonth = (dateTime) as nullable logical =>
Date.IsInPreviousNMonths(dateTime, 1);
shared Date.IsInPreviousNMonths = (dateTime, months as number) as nullable logical =>
Date.From(dateTime) >= Date.From(Date.StartOfMonth(Date.AddMonths(DateTime.FixedLocalNow(), -months))) and
Date.From(dateTime) < Date.From(Date.StartOfMonth(DateTime.FixedLocalNow()));
shared Date.IsInCurrentMonth = (dateTime) as nullable logical =>
Date.From(dateTime) >= Date.From(Date.StartOfMonth(DateTime.FixedLocalNow())) and
Date.From(dateTime) < Date.From(Date.AddDays(Date.EndOfMonth(DateTime.FixedLocalNow()), 1));
shared Date.IsInNextMonth = (dateTime) as nullable logical =>
Date.IsInNextNMonths(dateTime, 1);
shared Date.IsInNextNMonths = (dateTime, months as number) as nullable logical =>
Date.From(dateTime) >= Date.From(Date.AddDays(Date.EndOfMonth(DateTime.FixedLocalNow()), 1)) and
Date.From(dateTime) < Date.From(Date.AddDays(Date.EndOfMonth(Date.AddMonths(DateTime.FixedLocalNow(), months)), 1));
shared Date.IsInPreviousQuarter = (dateTime) as nullable logical =>
Date.IsInPreviousNQuarters(dateTime, 1);
shared Date.IsInPreviousNQuarters = (dateTime, quarters as number) as nullable logical =>
Date.From(dateTime) >= Date.From(Date.StartOfQuarter(Date.AddQuarters(DateTime.FixedLocalNow(), -quarters))) and
Date.From(dateTime) < Date.From(Date.StartOfQuarter(DateTime.FixedLocalNow()));
shared Date.IsInCurrentQuarter = (dateTime) as nullable logical =>
Date.From(dateTime) >= Date.From(Date.StartOfQuarter(DateTime.FixedLocalNow())) and
Date.From(dateTime) < Date.From(Date.AddDays(Date.EndOfQuarter(DateTime.FixedLocalNow()), 1));
shared Date.IsInNextQuarter = (dateTime) as nullable logical =>
Date.IsInNextNQuarters(dateTime, 1);
shared Date.IsInNextNQuarters = (dateTime, quarters as number) as nullable logical =>
Date.From(dateTime) >= Date.From(Date.AddDays(Date.EndOfQuarter(DateTime.FixedLocalNow()), 1)) and
Date.From(dateTime) < Date.From(Date.AddDays(Date.EndOfQuarter(Date.AddQuarters(DateTime.FixedLocalNow(), quarters)), 1));
shared Date.IsInPreviousYear = (dateTime) as nullable logical =>
Date.IsInPreviousNYears(dateTime, 1);
shared Date.IsInPreviousNYears = (dateTime, years as number) as nullable logical =>
Date.From(dateTime) >= Date.From(Date.StartOfYear(Date.AddYears(DateTime.FixedLocalNow(), -years))) and
Date.From(dateTime) < Date.From(Date.StartOfYear(DateTime.FixedLocalNow()));
shared Date.IsInCurrentYear = (dateTime) as nullable logical =>
Date.From(dateTime) >= Date.From(Date.StartOfYear(DateTime.FixedLocalNow())) and
Date.From(dateTime) < Date.From(Date.AddDays(Date.EndOfYear(DateTime.FixedLocalNow()), 1));
shared Date.IsInNextYear = (dateTime) as nullable logical =>
Date.IsInNextNYears(dateTime, 1);
shared Date.IsInNextNYears = (dateTime, years as number) as nullable logical =>
Date.From(dateTime) >= Date.From(Date.AddDays(Date.EndOfYear(DateTime.FixedLocalNow()), 1)) and
Date.From(dateTime) < Date.From(Date.AddDays(Date.EndOfYear(Date.AddYears(DateTime.FixedLocalNow(), years)), 1));
shared Date.IsInYearToDate = (dateTime) as nullable logical =>
Date.From(dateTime) >= Date.From(Date.StartOfYear(DateTime.FixedLocalNow())) and
Date.From(dateTime) < Date.From(Date.AddDays(Date.EndOfDay(DateTime.FixedLocalNow()), 1));
shared DateTime.IsInPreviousSecond = (dateTime) as nullable logical =>
DateTime.IsInPreviousNSeconds(dateTime, 1);
shared DateTime.IsInPreviousNSeconds = (dateTime, seconds as number) as nullable logical =>
DateTime.From(dateTime) >= StartOfSecond - #duration(0, 0, 0, seconds) and
DateTime.From(dateTime) < StartOfSecond;
shared DateTime.IsInNextSecond = (dateTime) as nullable logical =>
DateTime.IsInNextNSeconds(dateTime, 1);
shared DateTime.IsInNextNSeconds = (dateTime, seconds as number) as nullable logical =>
DateTime.From(dateTime) >= StartOfSecond + #duration(0, 0, 0, 1) and
DateTime.From(dateTime) < StartOfSecond + #duration(0, 0, 0, seconds + 1);
shared DateTime.IsInCurrentSecond = (dateTime) as nullable logical =>
DateTime.From(dateTime) >= StartOfSecond and
DateTime.From(dateTime) < StartOfSecond + #duration(0, 0, 0, 1);
shared DateTime.IsInPreviousMinute = (dateTime) as nullable logical =>
DateTime.IsInPreviousNMinutes(dateTime, 1);
shared DateTime.IsInPreviousNMinutes = (dateTime, minutes as number) as nullable logical =>
DateTime.From(dateTime) >= StartOfMinute - #duration(0, 0, minutes, 0) and
DateTime.From(dateTime) < StartOfMinute;
shared DateTime.IsInNextMinute = (dateTime) as nullable logical =>
DateTime.IsInNextNMinutes(dateTime, 1);
shared DateTime.IsInNextNMinutes = (dateTime, minutes as number) as nullable logical =>
DateTime.From(dateTime) >= StartOfMinute + #duration(0, 0, 1, 0) and
DateTime.From(dateTime) < StartOfMinute + #duration(0, 0, minutes + 1, 0);
shared DateTime.IsInCurrentMinute = (dateTime) as nullable logical =>
DateTime.From(dateTime) >= StartOfMinute and
DateTime.From(dateTime) < StartOfMinute + #duration(0, 0, 1, 0);
shared DateTime.IsInPreviousHour = (dateTime) as nullable logical =>
DateTime.IsInPreviousNHours(dateTime, 1);
shared DateTime.IsInPreviousNHours = (dateTime, hours as number) as nullable logical =>
DateTime.From(dateTime) >= StartOfHour - #duration(0, hours, 0, 0) and
DateTime.From(dateTime) < StartOfHour;
shared DateTime.IsInNextHour = (dateTime) as nullable logical =>
DateTime.IsInNextNHours(dateTime, 1);
shared DateTime.IsInNextNHours = (dateTime, hours as number) as nullable logical =>
DateTime.From(dateTime) >= StartOfHour + #duration(0, 1, 0, 0) and
DateTime.From(dateTime) < StartOfHour + #duration(0, hours + 1, 0, 0);
shared DateTime.IsInCurrentHour = (dateTime) as nullable logical =>
DateTime.From(dateTime) >= StartOfHour and
DateTime.From(dateTime) < StartOfHour + #duration(0, 1, 0, 0);
shared Date.MonthName = (date, optional culture as text) as nullable text =>
DateTimeZone.ToText(DateTimeZone.From(date), "MMMM", culture);
shared Date.DayOfWeekName = (date, optional culture as text) as nullable text =>
DateTimeZone.ToText(DateTimeZone.From(date), "dddd", culture);
StartOfHour = DateTime.From(Time.StartOfHour(DateTime.FixedLocalNow()));
StartOfMinute = DateTime.From(Time.StartOfHour(DateTime.FixedLocalNow()) + #duration(0, 0, Time.Minute(DateTime.FixedLocalNow()), 0));
StartOfSecond = DateTime.From(Time.StartOfHour(DateTime.FixedLocalNow()) + #duration(0, 0, Time.Minute(DateTime.FixedLocalNow()), Number.RoundDown(Time.Second(DateTime.FixedLocalNow()))));