teraslice icon indicating copy to clipboard operation
teraslice copied to clipboard

Data Mate Date functions

Open peterdemartini opened this issue 3 years ago • 9 comments

  • [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 just toDate 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') OR addToDate(years: 1, months: 1, hours: 2, minutes: 10, seconds: 100, milliseconds: 5)
  • [x] subtractFromDate(expr: '1h+2min') OR subtractFromDate(years: 1, months: 1, hours: 2, minutes: 10, seconds: 100, milliseconds: 5)
  • [x] getTimeBetween(end: '2001-01-01T01:00:00Z', format: '[optional format]') OR getTimeBetween(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)

peterdemartini avatar May 04 '21 21:05 peterdemartini

Updated for some clarification

peterdemartini avatar May 04 '21 21:05 peterdemartini

Added a bunch more validators

peterdemartini avatar May 04 '21 21:05 peterdemartini

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.

peterdemartini avatar May 04 '21 22:05 peterdemartini

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.

peterdemartini avatar May 04 '21 22:05 peterdemartini

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.

ciorg avatar May 11 '21 16:05 ciorg

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

peterdemartini avatar May 11 '21 16:05 peterdemartini

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.

ciorg avatar May 14 '21 00:05 ciorg

I'd probably guess we'd want to the UTC time for now until we add a general timezone support

peterdemartini avatar May 14 '21 16:05 peterdemartini

additional time functions:

  • setTimeZone(date) -> date
  • setUTC(date) -> date
  • getTimeZone(date) -> time zone string
  • getTimeZoneOffset(date) -> timezone offset
  • timezoneToOffset(time zone) -> offset in minutes

ciorg avatar May 18 '21 18:05 ciorg

I believe we have reasonable coverage on these now.

kstaken avatar Oct 07 '24 19:10 kstaken