-
Notifications
You must be signed in to change notification settings - Fork 236
Replace moment.js with custom date generator
#223
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
30d127c
add lockfile
zackschuster 06e844b
use custom rfc2822 date generator
zackschuster b92ae52
drop moment
zackschuster 4f5db54
update deps
zackschuster 5a074d1
add utc date generator
zackschuster 4ffeaf2
fix tests for varying timezones
zackschuster 8053ae0
fix missing test for getRFC2822Date
zackschuster 0a9bfd6
use regex for date tests
zackschuster 557c480
move date functions to separate files
zackschuster 8ccd207
use super-fancy destructuring, because i can
zackschuster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -6,5 +6,4 @@ | |
| *.swo | ||
| *~ | ||
|
|
||
| yarn.lock | ||
| package-lock.json | ||
This file contains hidden or 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,4 +1,5 @@ | ||
| exports.server = require('./smtp/client'); | ||
| exports.message = require('./smtp/message'); | ||
| exports.date = require('./smtp/date'); | ||
| exports.SMTP = require('./smtp/smtp'); | ||
| exports.error = require('./smtp/error'); |
This file contains hidden or 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
This file contains hidden or 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,29 @@ | ||
| function getRFC2822Date(date = new Date(), useUtc = false) { | ||
| if (useUtc) { | ||
| return getRFC2822DateUTC(date); | ||
| } | ||
|
|
||
| const dates = date | ||
| .toString() | ||
| .replace('GMT', '') | ||
| .replace(/\s\(.*\)$/, '') | ||
| .split(' '); | ||
|
|
||
| dates[0] = dates[0] + ','; | ||
|
|
||
| const day = dates[1]; | ||
| dates[1] = dates[2]; | ||
| dates[2] = day; | ||
|
|
||
| return dates.join(' '); | ||
| } | ||
|
|
||
| function getRFC2822DateUTC(date = new Date()) { | ||
| const dates = date.toUTCString().split(' '); | ||
| dates.pop(); // remove timezone | ||
| dates.push('+0000'); | ||
| return dates.join(' '); | ||
| } | ||
|
|
||
| exports.getRFC2822Date = getRFC2822Date; | ||
| exports.getRFC2822DateUTC = getRFC2822DateUTC; |
This file contains hidden or 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
This file contains hidden or 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,41 @@ | ||
| describe('rfc2822 dates', function() { | ||
| const { expect } = require('chai'); | ||
| const { | ||
| date: { getRFC2822Date, getRFC2822DateUTC }, | ||
| } = require('../email'); | ||
|
|
||
| var d_utc = dt => getRFC2822DateUTC(new Date(dt)); | ||
| var d = (dt, utc = false) => getRFC2822Date(new Date(dt), utc); | ||
|
|
||
| it('should match standard regex', function(done) { | ||
| // RFC 2822 regex: For details see https://tools.ietf.org/html/rfc2822#section-3.3 | ||
| // thanks to moment.js for the listing: https://github.com/moment/moment/blob/a831fc7e2694281ce31e4f090bbcf90a690f0277/src/lib/create/from-string.js#L101 | ||
| var rfc2822re = /^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),?\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|([+-]\d{4}))$/; | ||
| expect(d(0)).to.match(rfc2822re); | ||
| expect(d(329629726785)).to.match(rfc2822re); | ||
| expect(d(729629726785)).to.match(rfc2822re); | ||
| expect(d(1129629726785)).to.match(rfc2822re); | ||
| expect(d(1529629726785)).to.match(rfc2822re); | ||
|
|
||
| done(); | ||
| }); | ||
|
|
||
| it('should produce proper UTC dates', function(done) { | ||
| expect(d_utc(0)).to.equal('Thu, 01 Jan 1970 00:00:00 +0000'); | ||
| expect(d_utc(0)).to.equal(d(0, true)); | ||
|
|
||
| expect(d_utc(329629726785)).to.equal('Thu, 12 Jun 1980 03:48:46 +0000'); | ||
| expect(d_utc(329629726785)).to.equal(d(329629726785, true)); | ||
|
|
||
| expect(d_utc(729629726785)).to.equal('Sat, 13 Feb 1993 18:55:26 +0000'); | ||
| expect(d_utc(729629726785)).to.equal(d(729629726785, true)); | ||
|
|
||
| expect(d_utc(1129629726785)).to.equal('Tue, 18 Oct 2005 10:02:06 +0000'); | ||
| expect(d_utc(1129629726785)).to.equal(d(1129629726785, true)); | ||
|
|
||
| expect(d_utc(1529629726785)).to.equal('Fri, 22 Jun 2018 01:08:46 +0000'); | ||
| expect(d_utc(1529629726785)).to.equal(d(1529629726785, true)); | ||
|
|
||
| done(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
before there was a yarn/package.json lock file, i had some experience with even minor bumps introducing bugs that impacted deployments that did not intend to have anything upgraded.
now with locks, i don't see that happen as much. what are you thoughts on it? for dev dependencies, i don't think it matters as much, but for direct dependencies, it's worth thinking about.
since you removed moment and changed startls to be 'compatible' they are now all consistent. so that is good.
let me know what you think and we can run with this or to be safe we can change them all to be locked to one version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
personally my stance is, now that lockfiles are normalized, an end user can and should be able to ensure their builds are reproducible without libraries needing to pin themselves -- in fact, libraries should avail themselves of all the latest versions of libraries they can take without breaking tests. that's the best way (in my mind) to ensure the most secure and bug-free code is shipped.
that being said, latest version of node 6 ships with npm 3.10.3, and package-lock wasn't introduced until npm 5 -- i wouldn't want to dismiss people in that situation out-of-hand, knowing that e.g. joyent will still be on 0.10 for some time.
i wonder, though, if people in that situation would even bother touching their dependencies, especially if the next release is cut as semver major. it might be a moot point altogether, in which case i fall back to my original argument.