Skip to content

Commit

Permalink
chore: add compareDateTime
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon-He95 committed Apr 2, 2024
1 parent 2591ac0 commit d82512b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/date/compareDateTime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* 比较2个日期时间的大小
* @param date1 '2021-02-01 12:00:01' | '2021/02/01 12:00:01'
* @param date2 '2021-03-02 12:00:00' | '2021/03/02 12:00:00'
* @param separator '-' | '/' 默认 '-'
* @returns -1 | 1 | 0
*/
export function compareDateTime(date1: string, date2: string) {
const date1_time = new Date(date1.replace(/-/g, '/'))
const date2_time = new Date(date2.replace(/-/g, '/'))

if (date1_time < date2_time) return -1
if (date1_time > date2_time) return 1

return 0
}
File renamed without changes.
3 changes: 2 additions & 1 deletion src/date/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export * from './formateDate'
export * from './getDateList'
export * from './getDaysOfMonth'
export * from './createCanlendar'
export * from './createCalendar'
export * from './compareDate'
export * from './compareTime'
export * from './compareDateTime'
export * from './getFirstDay'

0 comments on commit d82512b

Please sign in to comment.