Skip to content

Commit

Permalink
fix(nc-gui): #7552 and #7557
Browse files Browse the repository at this point in the history
  • Loading branch information
rameshmane7218 committed Feb 15, 2024
1 parent a6eff9b commit 2343d7e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
7 changes: 5 additions & 2 deletions packages/nc-gui/composables/useMultiSelect/convertCellData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default function convertCellData(
}
return null
case UITypes.Date: {
const parsedDate = dayjs(value, column?.meta?.date_format ?? 'YYYY-MM-DD')
const parsedDate = dayjs(value, parseProp(column?.meta)?.date_format ?? 'YYYY-MM-DD')
if (!parsedDate.isValid()) {
if (isMultiple) {
return null
Expand All @@ -67,7 +67,10 @@ export default function convertCellData(
return parsedDate.format('YYYY-MM-DD')
}
case UITypes.DateTime: {
const parsedDateTime = dayjs(value)
const parsedDateTime = dayjs(
value,
`${parseProp(column?.meta)?.date_format ?? 'YYYY-MM-DD'} ${parseProp(column?.meta)?.time_format ?? 'HH:mm'}`,
)
if (!parsedDateTime.isValid()) {
if (isMultiple) {
return null
Expand Down
8 changes: 5 additions & 3 deletions packages/nc-gui/composables/useMultiSelect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
useI18n,
useMetas,
useUndoRedo,
parseProp,
} from '#imports'

const MAIN_MOUSE_PRESSED = 0
Expand Down Expand Up @@ -173,7 +174,7 @@ export function useMultiSelect(
})
}

if ([UITypes.DateTime, UITypes.CreatedTime, UITypes.LastModifiedTime].includes(columnObj.uidt)) {
if ([UITypes.DateTime, UITypes.CreatedTime, UITypes.LastModifiedTime].includes(columnObj.uidt as UITypes)) {
// remove `"`
// e.g. "2023-05-12T08:03:53.000Z" -> 2023-05-12T08:03:53.000Z
textToCopy = textToCopy.replace(/["']/g, '')
Expand All @@ -194,14 +195,15 @@ export function useMultiSelect(
// therefore, here we reformat to the correct datetime format based on the meta
textToCopy = d.format(constructDateTimeFormat(columnObj))

if (!dayjs(textToCopy).isValid()) {
if (!d.isValid()) {
// return empty string for invalid datetime
return ''
}
}

if (columnObj.uidt === UITypes.Date) {
const dateFormat = columnObj.meta?.date_format
const dateFormat = parseProp(columnObj.meta)?.date_format

if (dateFormat && isDateMonthFormat(dateFormat)) {
// any date month format (e.g. YYYY-MM) couldn't be stored in database
// with date type since it is not a valid date
Expand Down

0 comments on commit 2343d7e

Please sign in to comment.