108 lines
3.7 KiB
JavaScript
108 lines
3.7 KiB
JavaScript
'use strict';
|
|
|
|
import * as sol from "../../solight/sol.js";
|
|
|
|
|
|
const nowString = 'Now';
|
|
|
|
const absStartingString = 'Starting ';
|
|
const absStartedString = 'Since ';
|
|
const absEndingString = 'Until ';
|
|
const absEndedString = 'Ended ';
|
|
|
|
const relStartingString = 'Starts ';
|
|
const relStartedString = 'Started ';
|
|
const relEndingString = 'Ends ';
|
|
const relEndedString = 'Ended ';
|
|
|
|
const fuzzyMinutes = 1;
|
|
|
|
const nowish_interval = (time) =>
|
|
luxon.Interval.fromDateTimes(time.minus({minutes: fuzzyMinutes}), time.plus({minutes: fuzzyMinutes}));
|
|
|
|
const time_relative_string = (then, now) =>
|
|
then.setLocale('en').toRelative({base: now, unit: 'minutes'});
|
|
|
|
const start_relative_praefix_string = (event, time) =>
|
|
sol.isFutureEvent(event, time) ? relStartingString : relStartedString;
|
|
|
|
const end_relative_praefix_string = (event, time) =>
|
|
sol.isPastEvent(event, time) ? relEndedString : relEndingString;
|
|
|
|
const event_relative_start_time_string = (event, time) => {
|
|
const esd = sol.eventStartDate(event);
|
|
const startString = start_relative_praefix_string(event, time);
|
|
return startString.concat(time_relative_string(esd, time));
|
|
};
|
|
|
|
const event_relative_end_time_string = (event, time) => {
|
|
const eed = sol.eventEndDate(event);
|
|
const endString = end_relative_praefix_string(event, time);
|
|
return endString.concat(time_relative_string(eed, time));
|
|
};
|
|
|
|
const event_relative_fuzzy_start_time_string = (event, time) => {
|
|
const esd = sol.eventStartDate(event);
|
|
const startString = start_relative_praefix_string(event, time);
|
|
return nowish_interval(esd).contains(time) ?
|
|
nowString :
|
|
startString.concat(time_relative_string(esd, time));
|
|
};
|
|
|
|
const event_relative_fuzzy_end_time_string = (event, time) => {
|
|
const eed = sol.eventEndDate(event);
|
|
const endString = end_relative_praefix_string(event, time);
|
|
return nowish_interval(eed).contains(time) ?
|
|
nowString :
|
|
endString.concat(time_relative_string(eed, time));
|
|
};
|
|
|
|
|
|
const time_absolute_string = (time) =>
|
|
time.setLocale('en').toLocaleString({hour: '2-digit', minute: '2-digit', hourCycle: 'h23'});
|
|
|
|
const start_absolute_praefix_string = (event, time) =>
|
|
sol.isFutureEvent(event, time) ? absStartingString : absStartedString;
|
|
|
|
const end_absolute_praefix_string = (event, time) =>
|
|
sol.isPastEvent(event, time) ? absEndedString : absEndingString;
|
|
|
|
const event_absolute_start_time_string = (event, time) => {
|
|
const esd = sol.eventStartDate(event);
|
|
const startString = start_absolute_praefix_string(event, time);
|
|
return startString.concat(time_absolute_string(esd));
|
|
};
|
|
|
|
const event_absolute_end_time_string = (event, time) => {
|
|
const eed = sol.eventEndDate(event);
|
|
const endString = end_absolute_praefix_string(event, time);
|
|
return endString.concat(time_absolute_string(eed));
|
|
};
|
|
|
|
const event_absolute_fuzzy_start_time_string = (event, time) => {
|
|
const esd = sol.eventStartDate(event);
|
|
const startString = start_absolute_praefix_string(event, time);
|
|
return nowish_interval(esd).contains(time) ?
|
|
nowString :
|
|
startString.concat(time_absolute_string(esd));
|
|
};
|
|
|
|
const event_absolute_fuzzy_end_time_string = (event, time) => {
|
|
const eed = sol.eventEndDate(event);
|
|
const endString = end_absolute_praefix_string(event, time);
|
|
return nowish_interval(eed).contains(time) ?
|
|
nowString :
|
|
endString.concat(time_absolute_string(eed));
|
|
};
|
|
|
|
|
|
export {
|
|
event_relative_start_time_string,
|
|
event_relative_end_time_string,
|
|
event_relative_fuzzy_start_time_string,
|
|
event_relative_fuzzy_end_time_string,
|
|
event_absolute_start_time_string,
|
|
event_absolute_end_time_string,
|
|
event_absolute_fuzzy_start_time_string,
|
|
event_absolute_fuzzy_end_time_string
|
|
}
|