I'm having trouble understanding the workings of Luxon... I'm using Redux Toolkit to initialize the state as shown below
import {DateTime} from "luxon"
interface TestStateProps {
startDate: DateTime,
endDate: DateTime,
}
const initialTestState: TestStateProps {
startDate: DateTime.now(),
endDate: DateTime.now(),
}
export const testSlice = createSlice({
name: 'test',
initialTestState,
reducers: {
addDay: (state, action: PayloadAction<number>) => {
console.log(state.startDate instanceof DateTime)
console.log(JSON.stringify(state.startDate))
console.log(state.startDate.plus({days: action.payload }))
}
}
})
The output of the console.log
is not what I expected
console.log(state.startDate instanceof DateTime)
false
Why does it return false? I initialized it with DateTime.now()
console.log(JSON.stringify(state.startDate))
{"ts":1724911978667,"_zone":{},"loc":{"locale":"en-DE","numberingSystem":null,"outputCalendar":null,"weekSettings":null,"intl":"en-DE","weekdaysCache":{"format":{},"standalone":{}},"monthsCache":{"format":{},"standalone":{}},"meridiemCache":null,"eraCache":{},"specifiedLocale":null,"fastNumbersCached":null},"invalid":null,"weekData":null,"localWeekData":null,"c":{"year":2024,"month":8,"day":29,"hour":8,"minute":12,"second":58,"millisecond":667},"o":120,"isLuxonDateTime":true}
It seems like the expected result because of "isLuxonDateTime":true
. But why is
state.startDate instanceof DateTime
returning false? In the redux dev tools, it doesn't seem to be deserialized or something
https://i.sstatic.net/CbuAS2tr.png
eventually throws an errorconsole.log(state.startDate.plus({days: action.payload }))
Uncaught TypeError: state.startDate.plus is not a function
What am I missing here?