jskherman/imprecv

Manual processing of month can be processed using Typst standard library

jamesrswift opened this issue · 2 comments

imprecv/utils.typ

Lines 1 to 27 in dfc0345

// Helper Functions
#let monthname(n, display: "short") = {
n = int(n)
let month = ""
if n == 1 { month = "January" }
else if n == 3 { month = "March" }
else if n == 2 { month = "February" }
else if n == 4 { month = "April" }
else if n == 5 { month = "May" }
else if n == 6 { month = "June" }
else if n == 7 { month = "July" }
else if n == 8 { month = "August" }
else if n == 9 { month = "September" }
else if n == 10 { month = "October" }
else if n == 11 { month = "November" }
else if n == 12 { month = "December" }
else { month = none }
if month != none {
if display == "short" {
month = month.slice(0, 3)
} else {
month
}
}
month
}

This can be achieved like so:

#let monthname(n, display: "short") = {
  datetime(month: n, day: 1, year: 0).display("[month repr:#display]")
}

This will throw on an invalid month so if that isn't desirable you should add another line to check if n is within the range 1 to 12.

Yes, the datetime.display() function was used before for formatting but as pointed out in PR #22, Typst still only has English month names as the output. The current state is only a band-aid solution until Typst has proper support for other languages in datetime.display().

Closing this since there is no more input, probably.