-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4d2d6b1
commit d944ad3
Showing
2 changed files
with
58 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import getDayText from "./get-day-text"; | ||
import getEndOfDayDate from "./get-end-of-day-date"; | ||
import getFormattedTimeString from "./get-formatted-time-string"; | ||
import getShortTextDayMonthOptionalyear from "./get-short-text-day-month-optionalyear"; | ||
|
||
export default (dateTimeStringOrTimestampOrDate: string|number|Date): string => { | ||
const date: Date = new Date(dateTimeStringOrTimestampOrDate); | ||
|
||
if (date >= getEndOfDayDate(1)) { | ||
return getFormattedTimeString(date); | ||
} else if (date >= getEndOfDayDate(2)) { | ||
return 'Yesterday'; | ||
} else if (date >= getEndOfDayDate(7)) { | ||
return getDayText(date); | ||
} else { | ||
return getShortTextDayMonthOptionalyear(date); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import 'mocha'; | ||
import { assert } from 'chai'; | ||
import getBetterDate from '../src/get-better-date'; | ||
import getFormattedTimeString from '../src/get-formatted-time-string'; | ||
import getDayText from '../src/get-day-text'; | ||
import getEndOfDayDate from '../src/get-end-of-day-date'; | ||
|
||
describe('Get better date', () => { | ||
it('should return the date within same day', () => { | ||
const date: Date = getEndOfDayDate(); | ||
|
||
const expected = getFormattedTimeString(date); | ||
const actual = getBetterDate(date); | ||
assert.equal(actual, expected); | ||
}); | ||
|
||
it('should return the date within past day', () => { | ||
const date: Date = new Date(); | ||
|
||
date.setDate(date.getDate() - 1); // yesterday | ||
|
||
const expected = 'Yesterday'; | ||
const actual = getBetterDate(date); | ||
assert.equal(actual, expected); | ||
}); | ||
|
||
it('should return the date within same week', () => { | ||
const date: Date = new Date(); | ||
|
||
date.setDate(date.getDate() - 3); // 3 days | ||
|
||
const expected = getDayText(date); | ||
const actual = getBetterDate(date); | ||
assert.equal(actual, expected); | ||
}); | ||
|
||
it('should return the date in same year from a date object', () => { }); | ||
|
||
it('should return the date in different year from a date object', () => { }); | ||
}); |