score:2
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);
});
Source: stackoverflow.com
Related Query
- How to map/filter data correctly with luxon (DateTimeNow) and ReactJs
- how to correctly map an obj and return a single value with several identical values ReactJS
- how to properly replace axios api with fetch api and map over the received data in nodeJS?
- How to map inside map function and show the data in Reactjs
- How to paginate Cloud FireStore data with ReactJs and Hooks
- How can I Fetch and display Mysql data into ReactJS front end with Node JS as backend?
- How to map nested array in gatsby with reactjs and graphql
- How to get last data and set a color in map foreach in reactjs
- How to map and filter JSON with Javascript
- Displaying JSON multi-dimensional array data with ReactJS and map
- How to filter and map a list of items by targeting a property with javascript
- how to use react fetch() with useEffect hook and map the fetched data
- How to filter data at firestore (firebase) and get the filtered data? How to use "equal to" with db collection?
- How to iterate with Object Dot Keys and Array Dot Map to display data in a component?
- How do you loop through json with map and filter in React?
- How to filter items in a list with ReactJS and Redux?
- How to compare nested array with the map or filter and only return with first match inside?
- How to filter data from an array and display it accordingly using ReactJs
- How to filter and sort the same table data with React?
- How map with function and text ReactJs
- How to list a data inside another list using map and filter in React CLI (Comments List and Reply List)
- Reactjs - How to load and map data in reactjs material table
- Reactjs- Map and Filter JSON data with props
- How to map through an Array of object with the same data on some object and get it displayed once and also get other properties
- How to to filter the same data with 2 search bars - ReactJS
- Filter Blog data containing Multiple Tags with View Limit and Pagination in ReactJs
- How to get converted csv into json with fields and data format in reactjs
- How to load data from api and load component asynchronously with map function
- How to POST a JSON with data provided by user with REACTJS and Axios
- How to make API requests correctly with Reactjs and Axios?
More Query from same tag
- Why does 'useState()' appear not to be working?
- componentDidUpdate is not firing
- Why is day off by 1 and hours is way off on mor ISO 8601 in Moment js?
- use react hook value in formik onSubmit
- How to apply custom css styles to Kendo React Components?
- How to give preference to a my stylesheet over bootstrap in REACT(which is included in index.js file)?
- Rendering component after onClick
- Halt Execution of Network Request If It Takes Too Long?
- React route does not detect nesting routing and ids
- React, semantic-ui-react. Test suite failed to run: SyntaxError: Unexpected token import
- What is the TypeScript equivalent of “PropTypes.oneOfType”?
- react-bootstrap autoprefixer warning
- TypeError: Cannot read property 'map' of undefined state object inside array?
- How to write write if statement inside loop in reactjs
- storing normalized data with redux
- How to extend ReactJS' Link component and show innerHtml
- How to adjust MUI Tooltip font size?
- React-Redux and Websockets with socket.io
- styled component - nested conditional styling
- response.map() is not a function in reactjs
- Way to use validator.js with ReactJS?
- Window scroll event to check if the bottom of page is reached
- how to use css in JS for nested hover styles, Material UI
- How to add new elements to table using ReactJS
- ReactJS to present the data coming from a mongodbstitch into a table
- React: How to add HTMLElement?
- is there any way to run React + Django in same project without running npm run build again and again?
- How to show loading animation between React Router components
- Updating sibling component on an event in react js
- Access to Button click handler not executing in a webpack project