static LongRange dateStructureToTimestampRange(DateStructures.SomeDate d, DateInterpretationConfig config default new DateInterpretationConfig) { ret new DateStructureToTimestampRange(config).getRange(d); } sclass DateStructureToTimestampRange { TimeZone tz; long now; bool assumeFuture; delegate SomeDate to DateStructures. delegate Day to DateStructures. delegate Month to DateStructures. delegate Week to DateStructures. delegate Year to DateStructures. delegate CurrentWeekPlus to DateStructures. delegate CurrentMonthPlus to DateStructures. delegate CurrentYearPlus to DateStructures. delegate Weekday to DateStructures. delegate TodayPlus to DateStructures. delegate Hour to DateStructures. delegate Between to DateStructures. DateStructureToTimestampRange(DateInterpretationConfig config) { tz = config.timeZone; now = config.now; assumeFuture = config.assumeFuture; } Year currentYear() { ret new Year(year(now, tz)); } Month currentMonth() { ret new Month(month(now, tz), currentYear()); } SomeDate concretizeDate(SomeDate d) { if (d cast CurrentMonthPlus) d = new Month(month(now, tz) + d.nMonths, currentYear()); if (d cast TodayPlus) d = new Day(dayOfMonth(now, tz) + d.nDays, currentMonth()); if (d cast CurrentYearPlus) d = new Year(year(now, tz) + d.nYears); if (d cast CurrentWeekPlus) d = new Week(weekInYear(now, tz) + d.nWeeks, currentYear()); ret d; } LongRange getRange(SomeDate d) { d = concretizeDate(d); // year if (d cast Year) ret longRange(yearToTimestamp(d.year, tz), yearToTimestamp(d.year+1, tz)); // month if (d cast Month) { if (d.year == null) d.year = (Year) concretizeDate(new CurrentYearPlus(d.month < currentMonth().month ? 1 : 0)); int year = d.year.year; ret longRange( yearAndMonthToTimestamp(year, d.month, tz), yearAndMonthToTimestamp(year, d.month+1, tz)); } // week if (d cast Week) { int year = d.year.year; ret longRange( yearAndWeekToTimestamp(year, d.week, tz), yearAndWeekToTimestamp(year, d.week+1, tz)); } if (d cast Weekday) { if (d.week == null) d.week = (Week) concretizeDate(new CurrentWeekPlus(d.weekday < dayOfWeek_nr(now, tz) ? 1 : 0)); long start = getRange(d.week).start+(d.weekday-1)*24*60*60*1000; ret LongRange(start, start+24*60*60*1000); } // day if (d cast Day) { int month = d.month.month; int year = d.month.year.year; ret longRange( ymdToTimestamp(year, month, d.day, tz), ymdToTimestamp(year, month, d.day+1, tz)); } // hour if (d cast Hour) { if (d.isPM == null) fail("AM/PM unknown: " + d); long dayStart = getRange(assertNotNull("day of hour", d.day)).start; int actualHour = d.hour+(d.isPM ? 12 : 0); ret longRange(dayStart+hoursToMS(actualHour), dayStart+hoursToMS(actualHour+1)); } // between if (d cast Between) { ret longRange(getRange(d.from).start, getRange(d.to).start); } fail("dateStructureToTimestampRange: unknown type " + d); } }