Skip to content

refactor: replace lodash helpers with native alternatives - #45

Merged
nomiddlename merged 1 commit into
log4js-node:masterfrom
devoto13:dependencies
Jul 29, 2019
Merged

nomiddlename merged 1 commit into
log4js-node:masterfrom
devoto13:dependencies

Conversation

@devoto13

Copy link
Copy Markdown
Contributor

To reduce amount of non critical dependencies given that readability and expressiveness is comparable.

I just noticed that this PR conflicts a bit with https://github.com/log4js-node/streamroller/tree/simplify branch. I can rebase it once simplify is merged.

It also looks like it will be rather easy to eliminate async from production dependencies.

What do you think about these changes?

@nomiddlename

Copy link
Copy Markdown
Collaborator

Thanks for taking a look at this. I'm in favour of removing lodash - it's a big dependency. I do like that fact that its functions are all null-safe though; it simplifies some of the code. I'll merge the simplify branch anyway, and you can take a look at your changes again.

@devoto13

Copy link
Copy Markdown
Contributor Author

@nomiddlename I've pushed the update code. Please take a look.

PS On a side note these two tests failed on my machine because of different timezone.

@nomiddlename nomiddlename added this to the 2.0.0 milestone Jul 29, 2019
@nomiddlename

Copy link
Copy Markdown
Collaborator

Thanks for this.

What timezone are you in, by the way? I'll see if I can make those tests a bit more reliable.

@nomiddlename
nomiddlename merged commit 0e115e9 into log4js-node:master Jul 29, 2019
@devoto13

Copy link
Copy Markdown
Contributor Author

I'm in Central European Summer Time (GMT+2). Did some experiments in REPL:

> const df = require('date-format')
> df.parse('yyyy-MM-dd', '2019-07-29', new Date(0))
2019-07-28T23:00:00.000Z
> new Date(2019, 6, 29)
2019-07-28T22:00:00.000Z
> df.parse('yyyy-MM-dd', '2019-07-29', new Date(0)).toLocaleString()
'7/29/2019, 1:00:00 AM'
> new Date(2019, 6, 29).toLocaleString()
'7/29/2019, 12:00:00 AM'
> new Date(0).toLocaleString()
'1/1/1970, 1:00:00 AM'
> new Date(0, 0).toLocaleString()
'1/1/1900, 12:00:00 AM'

Looks like the first offender is new Date(0), which treats timestamp as UTC instead of current timezone (date-format parses rest of the components as local timezone) and sets wrong value for hours because of the offset. So I guess first thing is to replace it with new Date(0, 0), which would set minimal values for all time components in current timezone to align behaviour with date-format.

Once this is fixed you can replace timestamps in tests with new Date(2019, 6, 29).getTime() to make tests not sensitive to the timezone.

@devoto13
devoto13 deleted the dependencies branch July 29, 2019 13:50
devoto13 added a commit to devoto13/streamroller that referenced this pull request Jul 29, 2019
@nomiddlename

Copy link
Copy Markdown
Collaborator

Published to NPM in v2.0.0

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