Skip to content

Commit

Permalink
Fix invalid date
Browse files Browse the repository at this point in the history
  • Loading branch information
Marvin Heilemann committed Jan 10, 2020
1 parent 05db231 commit df17a2c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions content/writings/Der Morgen, die Nacht/index.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: Der Morgen, die Nacht
description: Ein kleines süßes Gedicht
created: 02-23-2015
modified: 07-12-2019
created: 2015-02-23
modified: 2019-07-12

header:
image: image.jpg
Expand Down
4 changes: 2 additions & 2 deletions content/writings/__demo__/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
title: Das ist, eine $" tolle Demo
description: Ein kleines süßes Gedicht
slug: custom slug
created: 09-23-2019
modified: 07-12-2019
created: 2019-09-23
modified: 2019-07-12

header:
image: image.jpg
Expand Down
12 changes: 9 additions & 3 deletions src/components/Time.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ import dayjs from 'dayjs'
import DataType from './DataType'

const Time = ({ date, format = 'L' }) => {
console.log(date)

if (!date) {
return <DataType tooltip="Not set" type="null"></DataType>
}

date = new Date(date)
const niceDate = dayjs(date).format(format)
const dateTime = dayjs(date).format()
const parsedDate = dayjs(date)
if (!parsedDate.isValid()) {
console.error('Date is not valid', date, parsedDate)
}

const niceDate = parsedDate.format(format)
const dateTime = parsedDate.format()

return <time dateTime={dateTime}>{niceDate}</time>
}
Expand Down

0 comments on commit df17a2c

Please sign in to comment.