score:2

Accepted answer

if you want to check if a given luxon datetime object represent the same day of today, you can use hassame passing date as second parameter

return whether this datetime is in the same unit of time as another datetime. higher-order units must also be identical for this function to return true. note that time zones are ignored in this comparison, which compares the local calendar time. use datetime#setzone to convert one of the dates if needed.

in your case, you can have something like the following code:

const datetime = luxon.datetime;
const input = [{
  status: "closed",
  createdat: "2022-01-13t15:28:25.239z"
}, {
  status: "closed",
  createdat: "2022-01-10t15:28:25.239z"
}, {
  status: "open",
  createdat: "2021-11-25t15:28:25.239z"
}, {
  status: "closed",
  createdat: new date().toisostring()
}];

const todayitems = input.filter(item => {
  return datetime.fromiso(item.createdat).hassame(datetime.now(), 'day') && item.status == "closed";
});
console.log(todayitems)
<script src="https://cdn.jsdelivr.net/npm/luxon@2.3.0/build/global/luxon.js"></script>

score:2

luxon has a function that let's you get a date at certain point of a parameter that's called startof. so you can do something like:

const todaydate = datetime.now().startof("day");

so your todaydate variable will be your current date, but at 00:00:00 time.

and you can make the transformation of the elements date during your filter function to compare them to todaydate like this:

//please consider that the example for today was at 2022-01-13
const array = [
  { 
    name: "this is for today", 
    date: "2022-01-13t15:28:25.239z" 
  }, 
  { 
    name: "this was for yesterday", 
    date: "2022-01-12t15:28:25.239z" 
  }];

const todaydate = datetime.now().startof("day");

const todayelements = array.filter((element) => {
  return datetime.fromiso(element.date).startof("day").equals(todaydate);
});

Related Query

More Query from same tag