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

Implement the Date standard library #357

Closed
wants to merge 1 commit into from

Conversation

LiaoPeng
Copy link
Contributor

@LiaoPeng LiaoPeng commented Dec 4, 2018

Implement the date standard library

Finished:

  • getFullYear, getMonth, getDate, getDay, getHours, getMinutes, getSeconds, getMilliseconds
  • setFullYear, setMonth, setDate, setHours, setMinutes, setSeconds, setMilliseconds
  • get UTC timestamp
  • enhancement the effective
  • getTimezoneOffset

@LiaoPeng LiaoPeng changed the title Implement the Implement the Date standard library Dec 4, 2018
std/assembly/date.ts Outdated Show resolved Hide resolved
@dcodeIO
Copy link
Member

dcodeIO commented Dec 7, 2018

One thing I am not sure of is that each Date instance has a new reference to BaseCalendar. Is this actually necessary? Looks like BaseCalendar could also be implemented in a more global/functional style so it doesn't have to allocate that much.

@LiaoPeng
Copy link
Contributor Author

It's not necessary. I would remove the BaseCalendar.

@LiaoPeng
Copy link
Contributor Author

I have a question how to get the local TimeZone. It blocked me.

@LiaoPeng
Copy link
Contributor Author

@MaxGraey
The method getTimezoneOffset Return the timezone difference between UTC and Local Time.
Both Date.utc and Date.now return the UTC time. I am not sure that's ok.

@dcodeIO
Copy link
Member

dcodeIO commented May 16, 2020

It's a shame that I haven't reviewed this more thoroughly. Looking at it again I think that this went stale in my head because it needs so many managed objects to represent a single date, and a more C-like implementation with data living on the date objects felt more efficient. In general I think that this is a good approach as it passes all the tests, so wondering if you are still interested in continuing on this PR?

@LiaoPeng
Copy link
Contributor Author

LiaoPeng commented Jul 1, 2020

@dcodeIO I'm very interested in this PR. The implementation of the date library referred the implementation of java date. If you think a more C-like implementation are more efficient. I would try it.

@dcodeIO
Copy link
Member

dcodeIO commented Jul 1, 2020

That would be fantastic, yeah. To elaborate a bit on the C-likeness, there currently are instances of CalendarDate and TimeZone required to represent a Date, so there's quite a bit of managed objects to reference count and collect. Ideally I think that having a std/util/calendar.ts exposing plain functions to work with let's say i64 values representing these would be more in-line with other stdlib internals, so that we have just a single allocation per Date instance to keep track of. Do you think it'd be possible to transform the existing code into this direction?

@MaxGraey
Copy link
Member

MaxGraey commented Jul 1, 2020

Also it will be ideal if you organize the code in such a way that it could be reused for Temporal proposal (https://github.com/tc39/proposal-temporal/tree/main/polyfill/lib) in future

@dcodeIO
Copy link
Member

dcodeIO commented Jul 1, 2020

Oh, wasn't aware of this one. Interesting.

@torch2424
Copy link
Contributor

@LiaoPeng Ah! Thank you very much for opening this! 😄 This is a ton of awesome work, it is super appreciated! 😄

While you work with @dcodeIO and @MaxGraey on building this out as a c-style API, and if you think it would take a while. I'd be interested in pulling this Date implementation into it's own library that could be npm install'd? I know it's not the most optimal for performance currently, but I think it'd be useful to a few folks in the communitty in the meantime 😄

That is of course, if you wouldn't mind me doing so (giving this PR and you full credit @LiaoPeng ) ? Or we could start it together? Whichever works!

Thanks y'all! 😄

Signed-off-by: Liao.Peng <pengliao@live.cn>
@LiaoPeng
Copy link
Contributor Author

@torch2424 Hey,it would take a while. Your advice is good, just do it. Now I push new commit rebased the current master branch.

@torch2424
Copy link
Contributor

torch2424 commented Feb 16, 2021

@LiaoPeng Ah! Thank you for rebasing! 😄 🙏

Your advice is good, just do it.

So just to confirm, you're okay with me using the code in the PR on a torch2424/as-date repo? (Pointing back to you and this PR of course) 😄

@LiaoPeng
Copy link
Contributor Author

@torch2424 I am okey,

@dcodeIO
Copy link
Member

dcodeIO commented Sep 27, 2022

Various Date functions have been implemented meanwhile, avoiding intermediary allocations.

@dcodeIO dcodeIO closed this Sep 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants