-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* fix: Invalid Date object will throw a TypeError (#58) * fixed lint error: unnecessary 'else' after 'return'
- Loading branch information
1 parent
b4ee644
commit 3747fa8
Showing
2 changed files
with
13 additions
and
2 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 |
---|---|---|
@@ -1,8 +1,14 @@ | ||
import { truncate } from './helpers' | ||
|
||
export default function inspectDate(dateObject, options) { | ||
// If we need to - truncate the time portion, but never the date | ||
const split = dateObject.toJSON().split('T') | ||
const stringRepresentation = dateObject.toJSON() | ||
|
||
if (stringRepresentation === null) { | ||
return 'Invalid Date' | ||
} | ||
|
||
const split = stringRepresentation.split('T') | ||
const date = split[0] | ||
// If we need to - truncate the time portion, but never the date | ||
return options.stylize(`${date}T${truncate(split[1], options.truncate - date.length - 1)}`, '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