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

DateTime Library Implementation #94

Merged
merged 68 commits into from
Sep 11, 2023
Merged

Conversation

CompeyDev
Copy link
Contributor

@CompeyDev CompeyDev commented Aug 24, 2023

This PR aims to implement a DateTime builtin library, inspired by the Roblox DateTime with some changes.

Things to implement before merge:

  • Implementing the create function and adding the builtin to mod.rs
  • LuaUserData trait implementations
  • Casting some rust types to lua and vice versa
    • Casting &str to Month is problematic, chrono maps "march" to Month::January
  • Creating the requireable table
  • Proper error handling
  • Documentation
  • Luau typing
  • QoL and Localization expansion
  • Tests & QA
    • Fix failing tests
      • DateTime::from_iso_date
      • DateTime::from_unix_timestamp
      • DateTime.toIsoDate()
      • DateTime.toUniversalTime()
    • Implement remaining tests
    • Fix failing LocalTime tests
    • Implement localization tests for LocalTime
  • Fix completely broken fromUniversalTime & fromLocalTime

image

  • Fix broken formatTime for conversion to local timezone

Closes #52.

* to_datetime_constructor (internal): converts DateTime to
  DateTimeConstructor
* to_local_time: converts DateTime to DateTimeConstructor with local
  timezone
* to_universal_time: converts DateTime to DateTimeConstructor with UTC
  timezone
* to_iso_date: converts DateTime to UTC ISO 8601 string
* format_time: formats the current DateTime to a string with a specified
  locale and timezone
@CompeyDev CompeyDev marked this pull request as draft August 24, 2023 15:17
@CompeyDev
Copy link
Contributor Author

CompeyDev commented Sep 7, 2023

Discovered something about the bug with formatTime. For local times conversions, when a timestamp from 2023 is used, an inaccurate time is returned. But when I swapped that timestamp with 1253731567 (a time in 2009), it functions as expected and returns the correct time.

What could be a reason for such behavior?

UPDATE: It functions as expected with any timestamp now, the issue was with the FromLua implementation for DateTimeBuilder, which was fixed in aa73a4b.

@CompeyDev
Copy link
Contributor Author

CompeyDev commented Sep 8, 2023

The only issue as of now for the tests to pass is that for localization tests. We need a certain locale to be included and the cache to updated, which requires superuser privileges. I've tried doing this on the rust side in tests.rs but its a bit tricky to non-interactively run sudo. Any other way we could go about doing this?

Relevant code:
https://github.com/filiptibell/lune/blob/be6b3f46fb95440d615bcc7574f8384259f70820/src/tests.rs#L16-L29

src/tests.rs Outdated Show resolved Hide resolved
@CompeyDev CompeyDev changed the title (Draft) DateTime Library Implementation DateTime Library Implementation Sep 10, 2023
Copy link
Collaborator

@filiptibell filiptibell left a comment

Choose a reason for hiding this comment

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

Thank you for implementing this! 🚀 I'll make the discussed changes some time this week, too

@filiptibell filiptibell merged commit e2aef01 into lune-org:main Sep 11, 2023
1 check passed
@CompeyDev
Copy link
Contributor Author

LGTM! 🚀

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.

Built-in library for date & time
3 participants