Skip to content

how to use date and durations in dataviewjs? #614

Answered by iwconfig
vitaly asked this question in Q&A
Discussion options

You must be logged in to vote

Use this.date.diffNow() or this.date.until(otherDate). And since luxon is available from inside dataviewjs, if you need to create new DateTime objects, you can do something like

const { DateTime, Duration } = luxon
const otherDate = DateTime.fromObject({ years: 3000, hours: 13, minutes: 37 })
const thatDuration = Duration.fromISOTime('13:37')
const thatIntervalButActuallyAnotherDuration = this.date.diffNow() // documentation says this returns an Interval but it's actually a Duration. Don't know why.
console.log(thatIntervalButActuallyAnotherDuration.plus(thatDuration).toObject())

Replies: 2 comments 9 replies

Comment options

You must be logged in to vote
2 replies
@vitaly
Comment options

@blacksmithgu
Comment options

Answer selected by vitaly
Comment options

You must be logged in to vote
7 replies
@blacksmithgu
Comment options

@wenlzhang
Comment options

@wenlzhang
Comment options

@blacksmithgu
Comment options

@pravin-d
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants