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

Add Date module #2799

Closed
wants to merge 7 commits into from
Closed

Add Date module #2799

wants to merge 7 commits into from

Conversation

jdharrisnz
Copy link

Type

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

Add Date module.

Related

N/A

Questions from me

Hi, my first time contributing to this! Hopefully this module is valuable and well-written.

I had some questions about code style and documentation.

First - @since tags - who adds these? I don't think I can do it since I don't know which version this might be added to.

Second - Predicate-based dual api functions. I've never seen these in Effect, but there are a few functions that offer optional arguments with default values, such as the week functions and their dowOffset. There's no difference between these usages:

pipe(Date.create(), Date.toWeekNumber)
pipe(Date.create(), Date.toWeekNumber(1))

...and TypeScript has no problem figuring out which overload to use, but it's a bit confusing to read.

Third - Is there some requirement for test coverage? I've added tests for everything that might be considered complex, but a lot of functions are also extremely trivial.

Fourth - I've added a lot in here and surely cover all the basics, but there's surely also more inspiration I could take from projects like date-fns. How comprehensive is something like this expected to be before it's accepted?

Thanks!

Copy link

changeset-bot bot commented May 21, 2024

🦋 Changeset detected

Latest commit: 42d8257

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 24 packages
Name Type
effect Minor
@effect/cli Major
@effect/experimental Major
@effect/opentelemetry Major
@effect/platform-browser Major
@effect/platform-bun Major
@effect/platform-node-shared Major
@effect/platform-node Major
@effect/platform Major
@effect/printer-ansi Major
@effect/printer Major
@effect/rpc-http Major
@effect/rpc Major
@effect/schema Major
@effect/sql-mssql Major
@effect/sql-mysql2 Major
@effect/sql-pg Major
@effect/sql-sqlite-bun Major
@effect/sql-sqlite-node Major
@effect/sql-sqlite-react-native Major
@effect/sql-sqlite-wasm Major
@effect/sql Major
@effect/typeclass Major
@effect/vitest Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@tim-smart
Copy link
Member

Hi, thanks for the PR :) Tackling a Date module is a brave first contribution lol.

First - @since tags - who adds these? I don't think I can do it since I don't know which version this might be added to.

You can add @since 3.3.0 for the time being.

Second - Predicate-based dual api functions. I've never seen these in Effect, but there are a few functions that offer optional arguments with default values, such as the week functions and their dowOffset. There's no difference between these usages:

I think what you have there is fine.

Third - Is there some requirement for test coverage? I've added tests for everything that might be considered complex, but a lot of functions are also extremely trivial.

It will be reviewed on a case by case basis. If we feel there are tests missing during review, we will let you know.

Fourth - I've added a lot in here and surely cover all the basics, but there's surely also more inspiration I could take from projects like date-fns. How comprehensive is something like this expected to be before it's accepted?

We will give your PR a proper review soon. A Date module has the potential to get quite complex (especially if you want to add timezone support etc), so sticking to the basics for now is a good choice.

@github-actions github-actions bot changed the base branch from main to next-minor May 23, 2024 19:48
@github-actions github-actions bot force-pushed the next-minor branch 17 times, most recently from 7a93c23 to e975f0e Compare May 28, 2024 23:20
@jdharrisnz
Copy link
Author

jdharrisnz commented Jul 17, 2024

Hi @tim-smart , is there anything I need to do to move this along, or still just waiting for code review?

I see one of the GitHub checks fails but I'm not sure what causes it.

@tim-smart
Copy link
Member

tim-smart commented Jul 18, 2024

Hi @tim-smart , is there anything I need to do to move this along, or still just waiting for code review?

I see one of the GitHub checks fails but I'm not sure what causes it.

Sorry for the neglect, but I think we just need to set aside some time to think about how we want to approach dates in effect.

Maybe we could introduce a UtcDate module first, which has APIs that only deal with UTC. Then afterwards look at how to add timezone support.

js Date also has so many footguns it might be better to side step it and create a more type safe data structure.

The upcoming Temporal proposal could be used as inspiration: https://tc39.es/proposal-temporal/docs/index.html

@tim-smart
Copy link
Member

I had a play around with the domain here: #3296

Not sure about the direction yet, but I think putting up some guard rails is a good approach.

@jdharrisnz
Copy link
Author

Thanks Tim. Agreed on shipping only UTC functions - there's a lot to keep in mind with the local stuff 😅

Your domain looks like a great start. Do you want me to move over the UTC getters, setters, and math functions from this PR into that? (Not sure how this fits with the WithZone part of it though - is that basically just an offset on top of UTC?)

@tim-smart
Copy link
Member

I think for time zones we can lean on the Intl APIs.

Yeah feel free to pitch in.

For the math functions it could be quite nice to have something like:

DateTime.add(self, 6, "months")
DateTime.add(self, Duration)

Then we can just "do the right thing" to prevent issues when crossing over daylight savings.

@github-actions github-actions bot force-pushed the next-minor branch 4 times, most recently from f9882d2 to 62ce405 Compare July 18, 2024 15:27
@tim-smart
Copy link
Member

Made some solid progress. Will close this in favour of the other PR.

@tim-smart tim-smart closed this Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants