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

fix: adjustments to the datetime library #6431

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

algebraic-dev
Copy link
Contributor

@algebraic-dev algebraic-dev commented Dec 20, 2024

This PR fix some issues that I found while using the library and other things that some people suggested

  • Fix timestamp Repr.
  • Add LeapTime and changed PlainTime : Type to PlainType : (leap : Bool) -> Type
  • Changed readlink -f to IO.FS.realPath

@algebraic-dev algebraic-dev requested a review from TwoFX as a code owner December 20, 2024 23:40
@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Dec 20, 2024
@leanprover-community-bot
Copy link
Collaborator

Mathlib CI status (docs):

  • ❗ Batteries CI can not be attempted yet, as the nightly-testing-2024-12-20 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-mathlib, Batteries CI should run now. (2024-12-20 23:58:12)

Copy link
Member

@tydeu tydeu left a comment

Choose a reason for hiding this comment

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

Thanks for the leap change! Hopefully, I will eventually be able to swap out Lake's TOML implementation of DateTime for the Std one.

@@ -28,9 +28,16 @@ structure PlainDateTime where
/--
The `Time` component of a `PlainTime`
-/
time : PlainTime
time : Sigma PlainTime
Copy link
Member

Choose a reason for hiding this comment

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

Did you consider also parameterizing PlainDateTime by leap as well?


namespace PlainTime

/--
Creates a `PlainTime` value representing midnight (00:00:00.000000000).
-/
def midnight : PlainTime :=
⟨0, 0, ⟨true, 0⟩, 0⟩
def midnight : PlainTime α :=
Copy link
Member

Choose a reason for hiding this comment

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

What is the rational behind using α and not leap for this parameter in these definitions? It seems that a name of leap would be better when users wish to set it using named parameters,

@@ -110,14 +111,14 @@ Converts a `PlainDate` to a `ZonedDateTime`.
-/
@[inline]
def ofPlainDate (pd : PlainDate) (zr : TimeZone.ZoneRules) : ZonedDateTime :=
ZonedDateTime.ofPlainDateTime (pd.atTime PlainTime.midnight) zr
ZonedDateTime.ofPlainDateTime (pd.atTime (α := true) PlainTime.midnight) zr
Copy link
Member

Choose a reason for hiding this comment

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

For example, these uses of (α := true) seem more readable as (leap := true).

/--
COMMENT
-/
def LeapTime := PlainTime True
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def LeapTime := PlainTime True
abbrev LeapTime := PlainTime True

I imagine this is still TODO (given the COMMENT), but I imagine this definitely should be an abbrev rather than a def to inherit the instances of PlainTime.

@@ -65,7 +65,7 @@ info: datetime("2000-01-19T03:02:01.000000000")
#guard_msgs in
#eval datetime - (1 : Day.Offset)

def time := time("13:02:01")
def time : PlainTime true := time("13:02:01")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def time : PlainTime true := time("13:02:01")
def time : LeapTime := time("13:02:01")

Maybe use this here and elsewhere (instead of PlainTime true)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants