Skip to content
This repository was archived by the owner on Jul 6, 2021. It is now read-only.

upgrade date-fns to v2 #108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"eslint-plugin-prettier": "^3.0.1",
"gh-pages": "^1.0.0",
"husky": "^1.3.1",
"ignore-loader": "^0.1.2",
"lint-staged": "^8.1.5",
"poi": "^12.5.6",
"postcss-nested": "^4.1.2",
Expand All @@ -60,7 +61,7 @@
]
},
"dependencies": {
"date-fns": "^1.29.0"
"date-fns": "^2.12.0"
},
"husky": {
"hooks": {
Expand Down
3 changes: 2 additions & 1 deletion poi.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module.exports = {
{
resourceQuery: /blockType=readme/,
loader: require.resolve('./example/vue-readme-loader')
}
},
{ test: /\.flow$/, loader: 'ignore-loader' }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed?

Copy link
Author

@nasermirzaei89 nasermirzaei89 Apr 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not an experienced frontend developer. But date-fns v2 have .js.flow files in its locales and WebPack needs a loader for these files.
You can remove this line and try to run yarn example.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

webpack will only process index.js, index.js.flow isn't used.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this line and try to run yarn example.
Webpack will throw an error for this file type.

]
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/converter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import toNow from 'date-fns/distance_in_words_to_now'
import toNow from 'date-fns/formatDistanceToNow'
import parseISO from 'date-fns/parseISO'

export default (date, locale, converterOptions) => {
if (typeof date === 'string') {
date = parseISO(date)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not simply new Date()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new Date??? <- this method will generate now.
we need to convert string dates before passing to date-fns.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

const { includeSeconds, addSuffix = true } = converterOptions
return toNow(date, {
locale,
Expand Down
12 changes: 9 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3057,9 +3057,10 @@ date-fns@^1.27.2:
resolved "https://registry.npmjs.org/date-fns/-/date-fns-1.30.1.tgz#2e71bf0b119153dbb4cc4e88d9ea5acfb50dc05c"
integrity sha512-hBSVCvSmWC+QypYObzwGOd9wqdDpOt+0wl0KbU+R+uuZBS1jN8VsD1ss3irQDknRj5NvxiTF6oj/nDRnN/UQNw==

date-fns@^1.29.0:
version "1.29.0"
resolved "https://registry.npmjs.org/date-fns/-/date-fns-1.29.0.tgz#12e609cdcb935127311d04d33334e2960a2a54e6"
date-fns@^2.12.0:
version "2.12.0"
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.12.0.tgz#01754c8a2f3368fc1119cf4625c3dad8c1845ee6"
integrity sha512-qJgn99xxKnFgB1qL4jpxU7Q2t0LOn1p8KMIveef3UZD7kqjT3tpFNNdXJelEHhE+rUgffriXriw/sOSU+cS1Hw==

date-now@^0.1.4:
version "0.1.4"
Expand Down Expand Up @@ -5199,6 +5200,11 @@ iferr@^1.0.2:
resolved "https://registry.npmjs.org/iferr/-/iferr-1.0.2.tgz#e9fde49a9da06dc4a4194c6c9ed6d08305037a6d"
integrity sha512-9AfeLfji44r5TKInjhz3W9DyZI1zR1JAf2hVBMGhddAKPqBsupb89jGfbCTHIGZd6fGZl9WlHdn4AObygyMKwg==

ignore-loader@^0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/ignore-loader/-/ignore-loader-0.1.2.tgz#d81f240376d0ba4f0d778972c3ad25874117a463"
integrity sha1-2B8kA3bQuk8Nd4lyw60lh0EXpGM=

ignore-walk@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/ignore-walk/-/ignore-walk-3.0.1.tgz#a83e62e7d272ac0e3b551aaa82831a19b69f82f8"
Expand Down