Skip to content

Commit

Permalink
chore: date core api changes (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pritish Budhiraja authored Feb 5, 2024
1 parent da9a7fa commit 85c784f
Show file tree
Hide file tree
Showing 24 changed files with 93 additions and 99 deletions.
32 changes: 14 additions & 18 deletions src/components/Calendar.res
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ module TableRow = {
"00",
"00",
)->Date.fromString
let dateToday = Js.Date.make()
let dateToday = Date.make()
let todayInitial = Js.Date.setHoursMSMs(
dateToday,
~hours=0.0,
Expand All @@ -78,7 +78,7 @@ module TableRow = {
(),
)
let isInCustomDisable = if customDisabledFutureDays > 0.0 {
date->Js.Date.getTime -. todayInitial <=
date->Date.getTime -. todayInitial <=
customDisabledFutureDays *. 24.0 *. 3600.0 *. 1000.0
} else {
false
Expand All @@ -87,8 +87,8 @@ module TableRow = {
| Some(obj) =>
if obj.startDate !== "" && obj.endDate !== "" {
!(
date->Js.Date.getTime -. obj.startDate->Date.fromString->Js.Date.getTime >= 0.0 &&
obj.endDate->Date.fromString->Js.Date.getTime -. date->Js.Date.getTime >= 0.0
date->Date.getTime -. obj.startDate->Date.fromString->Date.getTime >= 0.0 &&
obj.endDate->Date.fromString->Date.getTime -. date->Date.getTime >= 0.0
)
} else {
false
Expand All @@ -98,15 +98,15 @@ module TableRow = {
}

let isFutureDate = if disablePastDates {
todayInitial -. date->Js.Date.getTime <= 0.0
todayInitial -. date->Date.getTime <= 0.0
} else {
todayInitial -. date->Js.Date.getTime < 0.0
todayInitial -. date->Date.getTime < 0.0
}

let isInLimit = switch dateRangeLimit {
| Some(limit) =>
if startDate !== "" {
date->Js.Date.getTime -. startDate->Date.fromString->Js.Date.getTime <
date->Date.getTime -. startDate->Date.fromString->Date.getTime <
((limit->Js.Int.toFloat -. 1.) *. 24. *. 60. *. 60. -. 60.) *. 1000.
} else {
true
Expand All @@ -124,15 +124,15 @@ module TableRow = {
| true =>
switch onDateClick {
| Some(fn) =>
fn((Js.Date.toISOString(date)->DayJs.getDayJsForString).format(. "YYYY-MM-DD"))
fn((Date.toISOString(date)->DayJs.getDayJsForString).format(. "YYYY-MM-DD"))

| None => ()
}
| false => ()
}
}
let hSelf = highlight(
(Js.Date.toString(date)->DayJs.getDayJsForString).format(. "YYYY-MM-DD"),
(Date.toString(date)->DayJs.getDayJsForString).format(. "YYYY-MM-DD"),
)

let dayClass = if (
Expand All @@ -157,13 +157,11 @@ module TableRow = {
)
datevalue
}
let today = (Js.Date.make()->Js.Date.toString->DayJs.getDayJsForString).format(.
"YYYY-MM-DD",
)
let today = (Date.make()->Date.toString->DayJs.getDayJsForString).format(. "YYYY-MM-DD")

let renderingDate = (
getDate([Float.toString(year), Float.toString(month +. 1.0), obj])
->Js.Date.toString
->Date.toString
->DayJs.getDayJsForString
).format(. "YYYY-MM-DD")

Expand Down Expand Up @@ -227,9 +225,9 @@ module TableRow = {
)
}
let handleHover = () => {
let date = (Js.Date.toString(date)->DayJs.getDayJsForString).format(. "YYYY-MM-DD")
let date = (Date.toString(date)->DayJs.getDayJsForString).format(. "YYYY-MM-DD")
let parsedDate = getDate(String.split(date, "-"))
setHoverdDate(_ => parsedDate->Js.Date.toString)
setHoverdDate(_ => parsedDate->Date.toString)
switch setShowMsg {
| Some(setMsg) =>
if (
Expand Down Expand Up @@ -271,9 +269,7 @@ module TableRow = {
{cellRenderer(
obj == ""
? None
: Some(
(Js.Date.toString(date)->DayJs.getDayJsForString).format(. "YYYY-MM-DD"),
),
: Some((Date.toString(date)->DayJs.getDayJsForString).format(. "YYYY-MM-DD")),
)}
</span>
</AddDataAttributes>
Expand Down
4 changes: 2 additions & 2 deletions src/components/CalendarList.res
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ let make = (
let startMonth = switch month {
| Some(m) => Int.toFloat(Float.toInt(getMonthInFloat(m)))
| None => {
let tMonth = Int.toFloat(Float.toInt(Js.Date.getMonth(Js.Date.make())))
let tMonth = Int.toFloat(Float.toInt(Js.Date.getMonth(Date.make())))
disableFutureDates && count > 1 ? tMonth -. 1.0 : tMonth
}
}
let startYear = switch year {
| Some(y) => Int.toFloat(y)
| None => Js.Date.getFullYear(Js.Date.make())
| None => Js.Date.getFullYear(Date.make())
}
let (currDateIm, setCurrDate) = React.useState(() =>
Js.Date.makeWithYM(~year=startYear, ~month=startMonth, ())
Expand Down
2 changes: 1 addition & 1 deletion src/components/DatePicker.res
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ let make = (
onChange: timeValEv => {
let timeVal = timeValEv->Identity.formReactEventToString
if selectedDate !== "" {
let todayDayJsObj = Js.Date.make()->Js.Date.toString->DayJs.getDayJsForString
let todayDayJsObj = Date.make()->Date.toString->DayJs.getDayJsForString
let todayTime = todayDayJsObj.format(. "HH:mm:ss")
let todayDate = todayDayJsObj.format(. "YYYY-MM-DD")
let timeVal = if disableFutureDates && selectedDate == todayDate && timeVal > todayTime {
Expand Down
6 changes: 3 additions & 3 deletions src/components/DateRangePicker.res
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ let getTimeStringForValue = (
}

let getFormattedDate = (date, format) => {
date->Date.fromString->Js.Date.toISOString->TimeZoneHook.formattedISOString(format)
date->Date.fromString->Date.toISOString->TimeZoneHook.formattedISOString(format)
}

let isStartBeforeEndDate = (start, end) => {
Expand All @@ -80,7 +80,7 @@ let isStartBeforeEndDate = (start, end) => {

let getStartEndDiff = (startDate, endDate) => {
let diffTime = Math.abs(
endDate->Date.fromString->Js.Date.getTime -. startDate->Date.fromString->Js.Date.getTime,
endDate->Date.fromString->Date.getTime -. startDate->Date.fromString->Date.getTime,
)
diffTime
}
Expand Down Expand Up @@ -203,7 +203,7 @@ module Base = {
let dropdownPosition = isFilterSection && !isMobileView && isCustomSelected ? "right-0" : ""

let todayDayJsObj = React.useMemo1(() => {
Js.Date.make()->Js.Date.toString->DayJs.getDayJsForString
Date.make()->Date.toString->DayJs.getDayJsForString
}, [isDropdownExpanded])

let currentTime = todayDayJsObj.format(. "HH:mm")
Expand Down
2 changes: 1 addition & 1 deletion src/components/DynamicChart.res
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ let make = (

if sTime->String.length > 0 {
let {date, hour, minute, month, second, year} =
sTime->Date.fromString->Js.Date.toISOString->isoStringToCustomTimeZone
sTime->Date.fromString->Date.toISOString->isoStringToCustomTimeZone

dict->Dict.set(
"time_bucket",
Expand Down
4 changes: 2 additions & 2 deletions src/components/DynamicSingleStat.res
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ let make = (
(endTimeFromUrl->DayJs.getDayJsForString).subtract(.
1,
"hour",
).toDate(.)->Js.Date.toISOString
).toDate(.)->Date.toISOString
} else {
startTimeFromUrl
}
Expand Down Expand Up @@ -366,7 +366,7 @@ let make = (
(endTimeFromUrl->DayJs.getDayJsForString).subtract(.
1,
"hour",
).toDate(.)->Js.Date.toISOString
).toDate(.)->Date.toISOString
} else {
startTimeFromUrl
}
Expand Down
14 changes: 6 additions & 8 deletions src/components/InfraCalendar.res
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module TableRow = {
"00",
"00",
)->Date.fromString
let dateToday = Js.Date.make()
let dateToday = Date.make()
let todayInitial = Js.Date.setHoursMSMs(
dateToday,
~hours=0.0,
Expand All @@ -65,7 +65,7 @@ module TableRow = {
~milliseconds=0.0,
(),
)
let isFutureDate = todayInitial -. date->Js.Date.getTime < 0.0
let isFutureDate = todayInitial -. date->Date.getTime < 0.0

let onClick = _evt => {
let isClickDisabled = isFutureDate ? disableFutureDates : disablePastDates
Expand All @@ -74,15 +74,15 @@ module TableRow = {
switch onDateClick {
| Some(fn) =>
if obj !== "" {
fn((Js.Date.toISOString(date)->DayJs.getDayJsForString).format(. "YYYY-MM-DD"))
fn((Date.toISOString(date)->DayJs.getDayJsForString).format(. "YYYY-MM-DD"))
}
| None => ()
}
| false => ()
}
}
let hSelf = highlight(
(Js.Date.toString(date)->DayJs.getDayJsForString).format(. "YYYY-MM-DD"),
(Date.toString(date)->DayJs.getDayJsForString).format(. "YYYY-MM-DD"),
)

let dayClass = if (
Expand Down Expand Up @@ -159,9 +159,7 @@ module TableRow = {
{cellRenderer(
obj == ""
? None
: Some(
(Js.Date.toString(date)->DayJs.getDayJsForString).format(. "YYYY-MM-DD"),
),
: Some((Date.toString(date)->DayJs.getDayJsForString).format(. "YYYY-MM-DD")),
)}
</span>
</span>
Expand All @@ -188,7 +186,7 @@ let make = (
~disablePastDates=true,
~disableFutureDates=false,
) => {
// ~cellHighlighter: option<(~date: Js.Date.t) => highlighter>=None,
// ~cellHighlighter: option<(~date: Date.t) => highlighter>=None,
let _ = highLightList
let months = [Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec]
let heading = ["S", "M", "T", "W", "T", "F", "S"]
Expand Down
2 changes: 1 addition & 1 deletion src/components/InfraCalendarList.res
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ external ffInputToSelectInput: ReactFinalForm.fieldRenderPropsInput => ReactFina

let startYear = ref(2016)
let years = []
while Js.Date.make()->Js.Date.getFullYear->Float.toInt >= startYear.contents {
while Date.make()->Js.Date.getFullYear->Float.toInt >= startYear.contents {
years->Array.push(startYear.contents)->ignore
startYear := startYear.contents + 1
}
Expand Down
24 changes: 12 additions & 12 deletions src/components/NewCalendar.res
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module TableRow = {
"00",
"00",
)->Date.fromString
let dateToday = Js.Date.make()
let dateToday = Date.make()
let todayInitial = Js.Date.setHoursMSMs(
dateToday,
~hours=0.0,
Expand All @@ -74,21 +74,21 @@ module TableRow = {
(),
)
let isInCustomDisable = if customDisabledFutureDays > 0.0 {
date->Js.Date.getTime -. todayInitial <=
date->Date.getTime -. todayInitial <=
customDisabledFutureDays *. 24.0 *. 3600.0 *. 1000.0
} else {
false
}
let isFutureDate = if disablePastDates {
todayInitial -. date->Js.Date.getTime <= 0.0
todayInitial -. date->Date.getTime <= 0.0
} else {
todayInitial -. date->Js.Date.getTime < 0.0
todayInitial -. date->Date.getTime < 0.0
}

let isInLimit = switch dateRangeLimit {
| Some(limit) =>
if startDate !== "" {
date->Js.Date.getTime -. startDate->Date.fromString->Js.Date.getTime <
date->Date.getTime -. startDate->Date.fromString->Date.getTime <
((limit->Js.Int.toFloat -. 1.) *. 24. *. 60. *. 60. -. 60.) *. 1000.
} else {
true
Expand All @@ -109,15 +109,15 @@ module TableRow = {
| true =>
switch onDateClick {
| Some(fn) =>
fn((Js.Date.toISOString(date)->DayJs.getDayJsForString).format(. "YYYY-MM-DD"))
fn((Date.toISOString(date)->DayJs.getDayJsForString).format(. "YYYY-MM-DD"))

| None => ()
}
| false => ()
}
}
let hSelf = highlight(
(Js.Date.toString(date)->DayJs.getDayJsForString).format(. "YYYY-MM-DD"),
(Date.toString(date)->DayJs.getDayJsForString).format(. "YYYY-MM-DD"),
)

let dayClass = if (
Expand All @@ -141,13 +141,13 @@ module TableRow = {
)
datevalue
}
let today = (Js.Date.make()->Js.Date.toString->DayJs.getDayJsForString).format(.
let today = (Date.make()->Date.toString->DayJs.getDayJsForString).format(.
"YYYY-MM-DD",
)

let renderingDate = (
getDate([Float.toString(year), Float.toString(month +. 1.0), obj])
->Js.Date.toString
->Date.toString
->DayJs.getDayJsForString
).format(. "YYYY-MM-DD")
let isTodayHighlight =
Expand Down Expand Up @@ -282,9 +282,9 @@ module TableRow = {
)
}
let handleHover = () => {
let date = (Js.Date.toString(date)->DayJs.getDayJsForString).format(. "YYYY-MM-DD")
let date = (Date.toString(date)->DayJs.getDayJsForString).format(. "YYYY-MM-DD")
let parsedDate = getDate(String.split(date, "-"))
setHoverdDate(_ => parsedDate->Js.Date.toString)
setHoverdDate(_ => parsedDate->Date.toString)
switch setShowMsg {
| Some(setMsg) =>
if (
Expand Down Expand Up @@ -330,7 +330,7 @@ module TableRow = {
obj == ""
? None
: Some(
(Js.Date.toString(date)->DayJs.getDayJsForString).format(. "YYYY-MM-D"),
(Date.toString(date)->DayJs.getDayJsForString).format(. "YYYY-MM-D"),
),
)}
{isTodayHighlight
Expand Down
4 changes: 2 additions & 2 deletions src/components/NewCalendarList.res
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let make = (

let startYear = switch year {
| Some(y) => Int.toFloat(y)
| None => Js.Date.getFullYear(Js.Date.make())
| None => Js.Date.getFullYear(Date.make())
}
React.useEffect2(() => {
let fromDateJs = fromDate->DayJs.getDayJsForString
Expand Down Expand Up @@ -129,7 +129,7 @@ let make = (
let startMonth = switch month {
| Some(m) => Int.toFloat(Float.toInt(getMonthInFloat(m)))
| None => {
let tMonth = Int.toFloat(Float.toInt(Js.Date.getMonth(Js.Date.make())))
let tMonth = Int.toFloat(Float.toInt(Js.Date.getMonth(Date.make())))
disableFutureDates && count > 1 ? tMonth -. 1.0 : tMonth
}
}
Expand Down
Loading

0 comments on commit 85c784f

Please sign in to comment.