-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(date-picker): picker support timezone (#2104)
Co-authored-by: YanHui <[email protected]>
- Loading branch information
Showing
5 changed files
with
29 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,30 @@ | ||
import { isNumber } from 'lodash'; | ||
import moment from 'moment-timezone'; | ||
import momentTZ from 'moment-timezone'; | ||
import moment from 'moment'; | ||
import { format as dateFnsFormat } from 'date-fns-tz'; | ||
|
||
// 时间日期转换时区 moment | ||
export const parseTimeZone = (data?: any, format?: string) => | ||
moment(data as string, format).tz(localStorage.getItem('timezone') || 'UTC'); | ||
momentTZ(data as string, format).tz(localStorage.getItem('timezone') || 'UTC'); | ||
|
||
// 时间日期转换时区 date-fns | ||
export const parseFnsTimeZone = (date: number | Date | string, format: string) => { | ||
let finalDate = date; | ||
if (isNumber(date)) { | ||
finalDate = new Date(date); | ||
} | ||
|
||
return dateFnsFormat(finalDate, format, { | ||
timeZone: localStorage.getItem('timezone') || 'UTC', | ||
}); | ||
}; | ||
|
||
// 选择器时间按时区转化 | ||
// 例: date: Fri Oct 21 2022 09:00:00 GMT+0800 (中国标准时间) format: 'yyyy-MM-DD'; | ||
// return | ||
export const exportDateToZonedDate = (date: any, format?: string) => { | ||
if (!date) return date; | ||
return new Date( | ||
momentTZ.tz(moment(date).format(format || 'yyyy-MM-DD'), localStorage.getItem('timezone') || 'UTC').format() | ||
); | ||
}; |
43d2357
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
gio-design – ./
gio-design-git-master-growingio.vercel.app
gio-design.vercel.app
gio-design-growingio.vercel.app