How I can get the current year with the Js module of bucklescript?

64 Views Asked by At

I'm working on a ReasonReact project and I need to get the current year with the Js.Date module

I created a function to get a range between two years, so I need to pass the current year as the second parameter


let rangeYears = (startedYear, currentYear) =>
  Belt_Array.range(startedYear, currentYear) ->
  Array.to_list
  |> List.map(
    year => FormFieldSelect.{label: Js.Int.toString(year), value: `Int(year)}
  )
1

There are 1 best solutions below

0
fakenickels On BEST ANSWER

You can instantiate a new Date type and use getFullYear.

let date = Js.Date.make()
let year = date->Js.Date.getFullYear

or, one-liner

let year = Js.Date.(make()->getFullYear)