Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

64
LINES

< > BotCompany Repo | #1028541 // DateStructures

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (3370L/21K).

sclass DateStructures {
  asclass SomeDate {}
  asclass SomeDateDate > SomeDate {} // day or higher granularity
  asclass SomeTime > SomeDate {}
  asclass SomeWeek > SomeDateDate {}
  asclass DateProp > SomeDate {} // proposition on a date, e.g. a date range

  // years
  static transformable record Year(int year) > SomeDateDate {}
  static transformable record CurrentYearPlus(int nYears) > SomeDateDate {}
  
  // months
  static transformable record Month(int month, Year year) > SomeDateDate {
    Month(int month) { this(month, null); }
  }
  static transformable record CurrentMonthPlus(int nMonths) > SomeDateDate {}
  
  // weeks
  static transformable record Week(int week, Year year) > SomeWeek {}
  static transformable record CurrentWeekPlus(int nWeeks) > SomeWeek {}

  // days
  static transformable record Day(int day, Month month) > SomeDate {}
  static transformable record TodayPlus(int nDays) > SomeDate {}

  // weekdays
  static transformable record Weekday(int weekday, SomeWeek week) > SomeDateDate {
    // weekday is in Java count (1=Sunday)
    Weekday(int weekday) { this.weekday = weekday; }
  }

  // hours
  static transformable record Hour(int hour, Bool isPM, Day day) > SomeTime {
    Hour(int hour, Bool isPM) { this(hour, isPM, null); }
  }
  static transformable record CurrentHourPlus(int nHours) > SomeTime {}

  // minutes
  static transformable record Minute(int minute, Hour hour) > SomeTime {}
  static transformable record CurrentMinutePlus(int nMinutes) > SomeTime {}
  
  // seconds
  static transformable record Second(int second, Minute minute) > SomeTime {}
  
  // special stuff
  static transformable record BeginningOfTime > SomeDate {}
  static transformable record EndOfTime > SomeDate {}
  
  // date ranges & boolean operations
  static transformable record Between(SomeDate from, SomeDate to) > DateProp {}
  static transformable record Or(DateProp a, DateProp b) > DateProp {}
  static transformable record And(DateProp a, DateProp b) > DateProp {}
  static transformable record Not(DateProp a) > DateProp {}
  
  // some utility functions
  
  sbool containsTimes(SomeDate d) {
    ret defaultMetaTransformer().any(o -> o instanceof SomeTime, d);
  }
  
  sbool containsDateDates(SomeDate d) {
    ret defaultMetaTransformer().any(o -> o instanceof SomeDateDate, d);
  }
}

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: 288 / 673
Version history: 18 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)