teraslice
teraslice copied to clipboard
Data Mate Date functions
- [x]
isDate
- [x]
isEpoch(allowBefore1970: boolean)
- alias:isUnixTime
- [x]
isEpochMillis(allowBefore1970: boolean)
- [x]
isISO8601
- [x]
toDate(format: 'YYYY-mm-dd')
- [x]
formatDate(format: 'YYYY-mm-dd')
- [ ]
toISO8601
- this is basically justtoDate
with a format argument (I am not sure if we need it) - [ ]
toEpoch
- [ ]
toEpochMillis
- [x]
toYearlyDate
- [x]
toMonthlyDate
- [x]
toDailyDate
- [x]
toHourlyDate
- [x]
addToDate(expr: '1h+2min')
ORaddToDate(years: 1, months: 1, hours: 2, minutes: 10, seconds: 100, milliseconds: 5)
- [x]
subtractFromDate(expr: '1h+2min')
ORsubtractFromDate(years: 1, months: 1, hours: 2, minutes: 10, seconds: 100, milliseconds: 5)
- [x]
getTimeBetween(end: '2001-01-01T01:00:00Z', format: '[optional format]')
ORgetTimeBetween(start: '2001-01-01T01:00:00Z', format: '[optional format]')
- [x]
isBefore(date: '2001-01-01T01:00:00Z')
- [x]
isAfter(date: '2001-01-01T01:00:00Z')
- [x]
isBetween(start: '2001-01-01T01:00:00Z', end: '2005-01-01T01:00:00Z')
- [x]
getYears
- [x]
getMonths
- [x]
getHours
- [x]
getMinutes
- [x]
getSeconds
- [x]
getMilliseconds
- [x]
setYears
- [x]
setMonths
- [x]
setHours
- [x]
setMinutes
- [x]
setSeconds
- [x]
setMilliseconds
- [x]
isLeapYear
- [x]
isToday
- [x]
isYesterday
- [x]
isSunday
- [x]
isMonday
- [x]
isTuesday
- [x]
isWednesday
- [x]
isThursday
- [x]
isFriday
- [x]
isSaturday
- [x]
isWeekend
- [x]
isWeekday
- [x]
isFuture
- [x]
isPast
Future:
I am still not certain of these and it might be best to hold off on those for now.
-
isThisWeekend
-
isThisYear
-
isThisMonth
-
isThisHour
-
isThisMinute
-
isThisSecond
-
isThisMillisecond
(this may not be useful)
Updated for some clarification
Added a bunch more validators
I changed a few of the name and added a few more. I think there some question around the name getTimeBetween
and how it is overloaded with different behavior depending on the arg provided.
One thing we will need to be able to do, is pass set a "fixed" now date, that won't change throughout the lifetime of a query.
Thoughts on getTimeBetween, to make sure I'm on the correct path. Function to return the difference between 2 time stamps, right? Not sure if there is a clearer name. DurationBetween? Not sure if that is better.
There's an input value and then a start or an end. ~~Not sure if start or end is even needed, just the difference between the input and the 2nd time.~~ Start or end could indicate a positive or negative time between potentially.
Other thought is the return format - milliseconds, seconds, minutes, hours, days, months, years, or https://date-fns.org/v2.21.3/docs/formatISODuration.
There's also calendar months vs months, calendar weeks vs weeks, etc...
A lot of helpers methods in date-fn
, thankfully.
What if we added getDurationFrom(date: '2001-01-01T01:00:00Z')
and getDurationTo(date: '2001-01-01T01:00:00Z')
. Maybe we should just return milliseconds and then have a separate function for formatting the duration, like formatDuration
which would return a pretty formatted string
question on the getHours( but also applies to getDate, getMonth, etc...) the default function getHoursI) returns the hours in local time, even if a time zone is specified in the date. This is obviously not correct.
There is also a getUTCHours(). Which converts everything to utc and sends the hours.
for example - getHours('08/05/2021 EST')
, if using getUTCHours() returns 5. Which I would not expect...but should everything be standardized to UTC? Or am I missing another way to do this.
I'd probably guess we'd want to the UTC time for now until we add a general timezone support
additional time functions:
- setTimeZone(date) -> date
- setUTC(date) -> date
- getTimeZone(date) -> time zone string
- getTimeZoneOffset(date) -> timezone offset
- timezoneToOffset(time zone) -> offset in minutes
I believe we have reasonable coverage on these now.