Libraryless. Click here for Pure Java version (3370L/21K).
1 | sclass DateStructures {
|
2 | asclass SomeDate {}
|
3 | asclass SomeDateDate > SomeDate {} // day or higher granularity
|
4 | asclass SomeTime > SomeDate {}
|
5 | asclass SomeWeek > SomeDateDate {}
|
6 | asclass DateProp > SomeDate {} // proposition on a date, e.g. a date range
|
7 | |
8 | // years |
9 | static transformable record Year(int year) > SomeDateDate {}
|
10 | static transformable record CurrentYearPlus(int nYears) > SomeDateDate {}
|
11 | |
12 | // months |
13 | static transformable record Month(int month, Year year) > SomeDateDate {
|
14 | Month(int month) { this(month, null); }
|
15 | } |
16 | static transformable record CurrentMonthPlus(int nMonths) > SomeDateDate {}
|
17 | |
18 | // weeks |
19 | static transformable record Week(int week, Year year) > SomeWeek {}
|
20 | static transformable record CurrentWeekPlus(int nWeeks) > SomeWeek {}
|
21 | |
22 | // days |
23 | static transformable record Day(int day, Month month) > SomeDate {}
|
24 | static transformable record TodayPlus(int nDays) > SomeDate {}
|
25 | |
26 | // weekdays |
27 | static transformable record Weekday(int weekday, SomeWeek week) > SomeDateDate {
|
28 | // weekday is in Java count (1=Sunday) |
29 | Weekday(int weekday) { this.weekday = weekday; }
|
30 | } |
31 | |
32 | // hours |
33 | static transformable record Hour(int hour, Bool isPM, Day day) > SomeTime {
|
34 | Hour(int hour, Bool isPM) { this(hour, isPM, null); }
|
35 | } |
36 | static transformable record CurrentHourPlus(int nHours) > SomeTime {}
|
37 | |
38 | // minutes |
39 | static transformable record Minute(int minute, Hour hour) > SomeTime {}
|
40 | static transformable record CurrentMinutePlus(int nMinutes) > SomeTime {}
|
41 | |
42 | // seconds |
43 | static transformable record Second(int second, Minute minute) > SomeTime {}
|
44 | |
45 | // special stuff |
46 | static transformable record BeginningOfTime > SomeDate {}
|
47 | static transformable record EndOfTime > SomeDate {}
|
48 | |
49 | // date ranges & boolean operations |
50 | static transformable record Between(SomeDate from, SomeDate to) > DateProp {}
|
51 | static transformable record Or(DateProp a, DateProp b) > DateProp {}
|
52 | static transformable record And(DateProp a, DateProp b) > DateProp {}
|
53 | static transformable record Not(DateProp a) > DateProp {}
|
54 | |
55 | // some utility functions |
56 | |
57 | sbool containsTimes(SomeDate d) {
|
58 | ret defaultMetaTransformer().any(o -> o instanceof SomeTime, d); |
59 | } |
60 | |
61 | sbool containsDateDates(SomeDate d) {
|
62 | ret defaultMetaTransformer().any(o -> o instanceof SomeDateDate, d); |
63 | } |
64 | } |
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
| Snippet ID: | #1028541 |
| Snippet name: | DateStructures |
| Eternal ID of this version: | #1028541/19 |
| Text MD5: | 0a3212893f26c40e0db407a48c6d70af |
| Transpilation MD5: | 5f234156447a4495cb75747eb17374a5 |
| Author: | stefan |
| Category: | |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2020-06-28 16:52:54 |
| Source code size: | 2397 bytes / 64 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 518 / 945 |
| Version history: | 18 change(s) |
| Referenced in: | [show references] |