Skip to content

Commit

Permalink
Improved: changed the logic and only converting the date format on AP…
Browse files Browse the repository at this point in the history
…I call from ISO to Millis; rest remains on the basis of ISO(#619)

- Added a util function for conversion.
  • Loading branch information
R-Sourabh committed Jan 21, 2025
1 parent 153296c commit c0ef022
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/components/Filters.vue
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const query = computed(() => store.getters["count/getQuery"])
function openDateTimeModal(dateType: any, dateRange: any) {
currentFilter.value = `${dateType}_${dateRange}`;
currentDateTimeValue.value = query.value[dateType][dateRange] ? DateTime.fromMillis(query.value[dateType][dateRange]).toISO() : DateTime.now()
currentDateTimeValue.value = query.value[dateType][dateRange] ? query.value[dateType][dateRange] : DateTime.now()
dateTimeModalOpen.value = true;
}
Expand All @@ -153,14 +153,14 @@ async function updateDateTimeFilter(date: any) {
key: dateType,
value: {
...query.value[dateType],
[dateRange]: DateTime.fromISO(date).toMillis()
[dateRange]: date
}
}
await store.dispatch("count/updateQuery", payload)
}
function formatDateTime(date: number) {
const dateTime = DateTime.fromMillis(date);
function formatDateTime(date: any) {
const dateTime = DateTime.fromISO(date);
return dateTime.toFormat("dd'th' MMM yyyy");
}
Expand Down
14 changes: 7 additions & 7 deletions src/store/modules/count/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import RootState from "@/store/RootState"
import CountState from "./CountState"
import * as types from "./mutation-types"
import { CountService } from "@/services/CountService"
import { hasError, showToast, sortListByField } from "@/utils"
import { convertIsoToMillis, hasError, showToast, sortListByField } from "@/utils"
import { translate } from "@/i18n"
import router from "@/router"
import logger from "@/logger";
Expand Down Expand Up @@ -45,23 +45,23 @@ const actions: ActionTree<CountState, RootState> = {
if(state.query.createdDate) {
// created before date
if(state.query.createdDate?.thru) {
params["createdDate_thru"] = state.query.createdDate?.thru
params["createdDate_thru"] = convertIsoToMillis(state.query.createdDate.thru)
}
// created after date
if(state.query.createdDate?.from) {
params["createdDate_from"] = state.query.createdDate?.from
}
params["createdDate_from"] = convertIsoToMillis(state.query.createdDate.from)
}
}

if(state.query.closedDate) {
// closed before date
if(state.query.closedDate?.thru) {
params["closedDate_thru"] = state.query.closedDate?.thru
params["closedDate_thru"] = convertIsoToMillis(state.query.closedDate.thru)
}
// closed after date
if(state.query.closedDate?.from) {
params["closedDate_from"] = state.query.closedDate?.from
}
params["closedDate_from"] = convertIsoToMillis(state.query.closedDate.from)
}
}

try {
Expand Down
6 changes: 5 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ const getDateTime = (time: any) => {
return time ? DateTime.fromMillis(time).toISO() : ''
}

function convertIsoToMillis(isoDate: any) {
return DateTime.fromISO(isoDate).toMillis();
}

const getDerivedStatusForCount = (count: any) => {
const countStats = cycleCountStats(count.inventoryCountImportId)

Expand Down Expand Up @@ -178,4 +182,4 @@ function sortListByField(list: any, field = "parentProductName") {
});
}

export { downloadCsv, jsonToCsv, showToast, hasError, handleDateTimeInput, getCycleCountStats, getDateTime, getDateWithOrdinalSuffix, getDerivedStatusForCount, getFacilityName, getPartyName, getProductIdentificationValue, timeFromNow, parseCsv, sortListByField }
export { convertIsoToMillis, downloadCsv, jsonToCsv, showToast, hasError, handleDateTimeInput, getCycleCountStats, getDateTime, getDateWithOrdinalSuffix, getDerivedStatusForCount, getFacilityName, getPartyName, getProductIdentificationValue, timeFromNow, parseCsv, sortListByField }

0 comments on commit c0ef022

Please sign in to comment.