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

Range of Temporal? #682

Closed
Jack-Works opened this issue Jun 17, 2020 · 3 comments
Closed

Range of Temporal? #682

Jack-Works opened this issue Jun 17, 2020 · 3 comments
Labels
feedback v2? Candidate for being moved to a Temporal v2 proposal

Comments

@Jack-Works
Copy link
Member

for (const date of Temporal.range(
    new Temporal.Date(2020, 1, 1),
    new Temporal.Date(2020, 12, 31)
)) {
    console.log(date.toString())
}
// 2020-01-01
// 2020-01-02
// ...
// 2020-12-31
@ptomato
Copy link
Collaborator

ptomato commented Jun 17, 2020

With the current Temporal API this would be achievable by:

const start = new Temporal.Date(2020, 1, 1);
const end = new Temporal.Date(2020, 12, 31);
for (let date = start; !date.equals(end); date = date.plus({ days: 1 }))
    console.log(date.toString());

It's more typing, but on the other hand the step of 1 day is more explicit. (What should Temporal.range(Temporal.Time.from('00:00'), Temporal.Time.from('23:59')) produce?)

@MidnightDesign
Copy link

MidnightDesign commented Jan 8, 2021

Some kind of Range type would be great because it could have methods like intersects(other: Range): boolean, contains(instant: Instant | Range): boolean, endsBefore(other: Instant | Range): bool, get duration(): Duration, etc.

Edit: I just saw that this is being discussed in #205

@ptomato ptomato added the v2? Candidate for being moved to a Temporal v2 proposal label Jan 13, 2021
@ptomato
Copy link
Collaborator

ptomato commented Feb 12, 2021

This is not present in the revision of Temporal that's currently under review, but let's continue gathering information at js-temporal/proposal-temporal-v2#4.

@ptomato ptomato closed this as completed Feb 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feedback v2? Candidate for being moved to a Temporal v2 proposal
Projects
None yet
Development

No branches or pull requests

3 participants