Dataview: dateformat Luxon token for local week number and week year

I’m trying to create an index for my daily notes using dataviewjs, grouped by month and then by week number. The issue I’m running into is that the dateformat() function seems to play well only with the ISO week number (WW) and ISO week year (kkkk) tokens, and doesn’t seem to recognize local week number (nn) and local week year (iiii) tokens. (I’m using this Luxon token reference.)

For instance, this one-liner

dv.span(dv.func.dateformat(dv.func.date("2024-12-29"), "kkkk-WW"))

properly returns “2024-52”, but this code

dv.span(dv.func.dateformat(dv.func.date("2024-12-29"), "iiii-nn"))

returns “iiii-nn” rather than any proper date.

It’s not the end of the world if I can’t get the local week year format to work, but it just means I’ll have to live with weeks starting on a Monday rather than Sunday.

Thanks!

If that doesn’t work, why not try and use some mapping function? Some chat robot may help.

I see you’re using dataviewjs here, so then it’s an option to use moment.js for date manipulations. So I played a little bit around with using this test setup:

```dataviewjs

//const aDateStr = "2024-12-27"
const aDateStr = "2019-12-30"
const mDate = moment(aDateStr)
dv.paragraph("LUX date: " + dv.func.dateformat(dv.func.date(aDateStr), "yyyy-MM-dd"))

dv.paragraph("LUX kkkk-WW: " + dv.func.dateformat(dv.func.date(aDateStr), "kkkk-WW"))

dv.paragraph("LUX iiii-nn: " + dv.func.dateformat(dv.func.date(aDateStr), "iiii-nn"))

dv.paragraph("MOM date: " + mDate.format("YYYY-MM-DD"))
dv.paragraph("MOM GGGG-WW: " + mDate.format("GGGG-WW"))
dv.paragraph("MOM gggg-ww: " + mDate.format("gggg-ww"))

```

And for 2019-12-30 I got the following output:
image

However, I’m not why the luxon format codes are not working for either of us. I’m contemplating that it might be related to the locale not being set properly which I’ve experienced in some random settings before.

1 Like