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

refactor:(std/datetime) weekOfYear: Use constants, improve readability #6741

Merged
merged 6 commits into from
Jul 14, 2020
Merged

refactor:(std/datetime) weekOfYear: Use constants, improve readability #6741

merged 6 commits into from
Jul 14, 2020

Conversation

jsejcksn
Copy link
Contributor

@jsejcksn jsejcksn commented Jul 14, 2020

Related issue: #6601
Related PR: #6659

This PR improves readability for code and documentation.

I noticed the use of literal millisecond and integer values, and an opportunity to remove some comments and improve code readability, so I refactored it, using constants instead of the literals.

The new tests are sourced from moment.js.

@CLAassistant
Copy link

CLAassistant commented Jul 14, 2020

CLA assistant check
All committers have signed the CLA.

@jsejcksn
Copy link
Contributor Author

While working on this, I felt a pull to add a currentWeekOfYear function to mirror the currentDayOfYear function. However, I'm not sure what real value that would add, since it's a very simple abstraction—literally:

weekOfYear(new Date());

This made me wonder further: what is the defined purpose of std/datetime? These kinds of functions already exist elsewhere in dedicated libraries like date-fns, moment, luxon, etc. However, the style guide states Do not depend on external code, so is the aim to re-invent the wheel or copy from them?

Comment on lines +11 to +21
const DAYS_PER_WEEK = 7;

enum Day {
Sun,
Mon,
Tue,
Wed,
Thu,
Fri,
Sat,
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should these be exported, or kept private unless/until needed? I didn't see any guidelines about conditions for exporting, keeping exports to a minimal, etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

I suggested to remove the currentDayOfYear in that issue.

As for the purpose of std/datetime: I think a clear definition has to be worked out still, but I think it is a good addition as a std library. In my view the module has theses purposes at the moment:

  • provide commonly used functions related to date and time
  • provide datetime parser and formatter

I think some 3rd party libraries do the one, some the other.
I did a PR to add a generic parser and a formatter. In a sense some features are reinventing the wheel (like parser and formatter) but the attention lies to provide compatibility with Intl.
Also this module will likely change once this proposal is at stage 4.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Temporal looks like a step forward. 🧗

@bartlomieju Any feedback about exports?

@jsejcksn
Copy link
Contributor Author

Re: fmt

I ran:

./tools/format.py

from the repo root directory, but it exited with an error. I don't remember the exact error, but I'm wondering if that step can be added to the repo actions, since I'm not the first to run into this problem.

Related: Is deno fmt equivalent to the python formatter for TS/JS files?

@bartlomieju
Copy link
Member

This made me wonder further: what is the defined purpose of std/datetime? These kinds of functions already exist elsewhere in dedicated libraries like date-fns, moment, luxon, etc. However, the style guide states Do not depend on external code, so is the aim to re-invent the wheel or copy from them?

The purpose for datetime/ hasn't really been defined. It's definitely useful to have date manipulation utilities in standard library, but the scope hasn't been set. Before stabilizing std/ we'll reevaluate each module.

from the repo root directory, but it exited with an error. I don't remember the exact error, but I'm wondering if that step can be added to the repo actions, since I'm not the first to run into this problem.

This issue should be resolved when #6682 lands.

Related: Is deno fmt equivalent to the python formatter for TS/JS files?

No, it's not, current repository uses prettier.

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

LGTM - thanks!

@ry ry merged commit d49a021 into denoland:master Jul 14, 2020
@jsejcksn jsejcksn deleted the std-weekOfYear branch July 15, 2020 00:21
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 21, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 24, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 24, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 24, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Feb 1, 2021
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.

None yet

5 participants