Skip to content

Commit 8557eb3

Browse files
authored
Merge pull request #111 from JulienGasparLopes/default-date-format-for-worksheet-parsing
Default date format for worksheet parsing
2 parents 82a97bc + b2b9817 commit 8557eb3

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

src/ReactSpreadsheetImport.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const defaultRSIProps: Partial<RsiProps<any>> = {
1717
uploadStepHook: async (value) => value,
1818
selectHeaderStepHook: async (headerValues, data) => ({ headerValues, data }),
1919
matchColumnsStepHook: async (table) => table,
20+
dateFormat: "yyyy-mm-dd", // ISO 8601
2021
} as const
2122

2223
export const ReactSpreadsheetImport = <T extends string>(props: RsiProps<T>) => {

src/steps/UploadStep/components/DropZone.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type DropZoneProps = {
1313
}
1414

1515
export const DropZone = ({ onContinue, isLoading }: DropZoneProps) => {
16-
const { translations, maxFileSize } = useRsi()
16+
const { translations, maxFileSize, dateFormat } = useRsi()
1717
const styles = useStyleConfig("UploadStep") as typeof themeOverrides["components"]["UploadStep"]["baseStyle"]
1818
const toast = useToast()
1919
const [loading, setLoading] = useState(false)
@@ -39,7 +39,7 @@ export const DropZone = ({ onContinue, isLoading }: DropZoneProps) => {
3939
onDrop: async ([file]) => {
4040
setLoading(true)
4141
const arrayBuffer = await readFileAsync(file)
42-
const workbook = XLSX.read(arrayBuffer)
42+
const workbook = XLSX.read(arrayBuffer, { cellDates: true, dateNF: dateFormat })
4343
setLoading(false)
4444
onContinue(workbook)
4545
},

src/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ export type RsiProps<T extends string> = {
3737
autoMapHeaders?: boolean
3838
// Headers matching accuracy: 1 for strict and up for more flexible matching
3939
autoMapDistance?: number
40-
// initial Step state to be rendered on load
40+
// Initial Step state to be rendered on load
4141
initialStepState?: StepState
42+
// Date format to use
43+
dateFormat?: string
4244
}
4345

4446
export type RawData = Array<string | undefined>

0 commit comments

Comments
 (0)