Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added method _isNotExpired #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

jzarca01
Copy link

If there is no expirationDate specified in the license then it returns true, otherwise it checks if today is before or same day as expirationDate

@@ -15,79 +17,75 @@ A lightweight License file generator and parser for NodeJS.
## Generating license file

```javascript
const licenseFile = require('nodejs-license-file');
const licenseFile = require("nodejs-license-file");
Copy link

Choose a reason for hiding this comment

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

Why change the string quotes convention?

Copy link
Author

Choose a reason for hiding this comment

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

My linter did that

Copy link

Choose a reason for hiding this comment

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

This project does not have an .eslintrc file so you shouldn't be applying your personal preferences to it. It's better to maintain the existing conventions.

firstName: "Name",
lastName: "Last Name",
email: "[email protected]",
expirationDate: "2025-11-15"
Copy link

Choose a reason for hiding this comment

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

Why change the date format? Used to be separated by /, and now separated by -.

Copy link
Author

Choose a reason for hiding this comment

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

dayjs handles date with this specific format by default, plus it's less confusing
I didnt know in the first place if it was DD/MM/YYYY or MM/DD/YYYY

@@ -28,6 +28,7 @@
},
"homepage": "https://github.com/bushev/nodejs-license-file",
"dependencies": {
"dayjs": "1.8.17",
Copy link

Choose a reason for hiding this comment

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

It's trivial to compare dates in JavaScript, so you don't need a dependency for that.

Copy link
Author

Choose a reason for hiding this comment

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

It's easier to manipulate dates with dayjs, which is the lightest date library I've found

Copy link

Choose a reason for hiding this comment

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

While that's true, the manipulation that you perform is rather trivial even without a library.
In lib/index.js:239 you're just comparing two dates. I'll comment there directly.

@@ -0,0 +1,218 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
Copy link

Choose a reason for hiding this comment

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

The project doesn't currently have a yarn.lock, so please don't commit one.

@soryy708
Copy link

soryy708 commented Dec 5, 2019

That's a useful feature that we're currently doing in application code instead of via the dependency.

const expirationDate = data.expirationDate;
const isBefore = dayjs().isBefore(dayjs(expirationDate));
const isSame = dayjs().isSame(dayjs(expirationDate))
return isBefore || isSame;
Copy link

@soryy708 soryy708 Dec 6, 2019

Choose a reason for hiding this comment

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

What I see you're doing is checking if now <= expirationDate. You don't need a library for that.

I believe you can compare two plain JavaScript date objects with the <= operator directly.
If that's hard to grasp, you can also convert them to a UNIX timestamp (a number) and compare those.
https://stackoverflow.com/questions/492994/compare-two-dates-with-javascript

You can get a date object of the current time via the date constructor without parameters new Date(). Alternatively, you can get the UNIX timestamp by calling Date.now().

So, it would be something like:
return (new Date()) <= new Date(expirationDate)
or
return Date.now() <= (new Date(expirationDate)).getTime()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants