3

i have a calendar in my site which take a start date and end date and pass them into a function who calculates the dates between . lets sat we have the start date Mon Mar 29 2021 03:00:00 GMT+0300 (Eastern European Summer Time) and the end date is Mon Apr 05 2021 03:00:00 GMT+0300 (Eastern European Summer Time) ; this function should return ["30/3/2021","31/3/2021","1/4/2020","2/4/2020","3/4/2020","4/4/2020"]

let getDatesInRange = (start, end) => {
  let dates = ref([])
  let current = ref(start)

  while current.contents <= end {
    dates := dates.contents->Js.Array2.concat([current.contents->toUTCDateString])
    current := {
        let date = current.contents->toUTCDateString->Js.Date.fromString
        date->Js.Date.setDate(date->Js.Date.getDate +. 1.0)->ignore

        date
      }
  }

  dates.contents
}

and this is toUTCDateString function which take a date and give the string version of it

let toUTCDateString = date => {
  let date = date->External.unSafeCastToJsObject

  date["toISOString"]()["split"]("T")[0]
}

These functions where working fine until The time has changed for Daylight Saving Time; we gain an hour so the day stuck there in for some reason Any body face this issue before and who to deal with such time issues ?

Jhecht
  • 4,407
  • 1
  • 26
  • 44
  • in regular js I would ask why you just weren't using the `toLocaleDateString` function I do not know rescript so I'm sure you must have your reasons – Jhecht Apr 05 '21 at 07:01

0 Answers0