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

feat: add date and time functionality #4904

Merged
merged 131 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
9c1be6c
feat: add datetime library
algebraic-dev Aug 2, 2024
856f569
chore: remove useless piece of code
algebraic-dev Aug 2, 2024
a9bf653
feat: format and moved the folder to the right place
algebraic-dev Aug 5, 2024
36108dd
Merge branch 'leanprover:master' into master
algebraic-dev Aug 7, 2024
a2e3a4e
feat: api docs, parser changes, notation, renames and improve documen…
algebraic-dev Aug 7, 2024
21563e8
refactor: rename some functions
algebraic-dev Aug 7, 2024
e0da8a6
feat: zone rules
algebraic-dev Aug 9, 2024
5e269e2
fix: wrong import
algebraic-dev Aug 9, 2024
8d0f196
feat: add io functions for timestamp and instant
algebraic-dev Aug 9, 2024
2c8ef66
feat: removes LE, adds a bunch of add and sub functions, move interva…
algebraic-dev Aug 14, 2024
858415c
chore: fix comment
algebraic-dev Aug 14, 2024
882fb0e
style: fix comment whitespaces
algebraic-dev Aug 14, 2024
5c01abe
style: fix whitespaces between declarations
algebraic-dev Aug 14, 2024
cf9b567
style: fix some comments and add prelude on the top
algebraic-dev Aug 14, 2024
5d058ad
feat: add parsing functions
algebraic-dev Aug 14, 2024
4e3b9b1
style: rename function and whitespace
algebraic-dev Aug 14, 2024
abfd3be
style: add prelude import
algebraic-dev Aug 14, 2024
bd236c1
style: reorder imports and comments
algebraic-dev Aug 15, 2024
4032ad2
feat: isDST flag for timezones
algebraic-dev Aug 15, 2024
2376e62
feat: a lot of conversion functions
algebraic-dev Aug 15, 2024
d53c100
style: fix some comments
algebraic-dev Aug 16, 2024
f724551
feat: add some functions and tests
algebraic-dev Aug 16, 2024
248ed5e
feat: add missing functions
algebraic-dev Aug 16, 2024
58a446b
fix: wrong comments
algebraic-dev Aug 16, 2024
c480249
fix: some small fixes and add things to duration
algebraic-dev Aug 19, 2024
9abb7b6
fix: small bugs and tests
algebraic-dev Aug 20, 2024
e9be735
fix: a bunch of problems and added tests
algebraic-dev Aug 20, 2024
89cfd2c
refactor: some structures and add test
algebraic-dev Aug 21, 2024
b193aac
feat: change some native functions
algebraic-dev Aug 23, 2024
a48f4ff
fix: bug with timezone change in localdatetime
algebraic-dev Aug 23, 2024
7b5754e
feat: add format functions
algebraic-dev Aug 23, 2024
842fb3b
feat: add a bunch of arithmetic functions
algebraic-dev Aug 23, 2024
3b83c6c
feat: add more sub and add functions
algebraic-dev Aug 23, 2024
d1bef18
test: add test for time operations
algebraic-dev Aug 23, 2024
ee0578f
chore: remove useless comments
algebraic-dev Aug 23, 2024
ab1d8cd
feat: changed function names and added ofSeconds and ofNanoseconds to…
algebraic-dev Aug 23, 2024
cafb98f
chore: reverting the branch :/
algebraic-dev Aug 26, 2024
c82e856
chore: reverting the branch :/
algebraic-dev Aug 26, 2024
073409d
Merge branch 'master' of github.com:leanprover/lean4
algebraic-dev Aug 26, 2024
091a969
refactor: changes Rat to Std.Internal and Parsec imports that was broken
algebraic-dev Aug 26, 2024
6c3cec4
refactor: changed names add some utilitary functions
algebraic-dev Aug 28, 2024
c30e4a1
feat: add conversion functions
algebraic-dev Aug 28, 2024
ada5670
fix: problems with since functions
algebraic-dev Aug 28, 2024
408fc65
tests: add more tests
algebraic-dev Aug 28, 2024
3f9899b
feat: add more conversion functions for timestamp
algebraic-dev Aug 28, 2024
ebadb4f
feat: remove notation import
algebraic-dev Aug 28, 2024
8e0794f
fix: problems with tests and function names
algebraic-dev Aug 28, 2024
0f755ec
fix: tests using Rat
algebraic-dev Aug 28, 2024
751b852
fix: update src/Std/Time/Duration.lean
algebraic-dev Aug 28, 2024
ec3968c
fix: update src/Std/Time.lean message
algebraic-dev Aug 28, 2024
86fec58
style: remove whitspace.
algebraic-dev Aug 28, 2024
3dabdcd
refactor: change Timestamp to depend on Duration
algebraic-dev Aug 28, 2024
1cccd65
refactor: fix some function names
algebraic-dev Aug 28, 2024
b1da2da
feat: add some class operations that result in durations
algebraic-dev Aug 28, 2024
7bc1a7c
feat: adjust pretty printing and notation for dates
algebraic-dev Aug 28, 2024
fe48007
refactor: modified each formatter to use the a default format that ca…
algebraic-dev Aug 28, 2024
f85c0cf
feat: add a bunch of conversion functions and fixes
algebraic-dev Aug 29, 2024
79c90c9
refactor: change notation syntax, add error handling for the get_time…
algebraic-dev Aug 30, 2024
b32c8a6
fix: avoid creating new tokens
algebraic-dev Aug 30, 2024
60f5b92
refactor: rename err to tm_ptr in io.cpp
algebraic-dev Sep 2, 2024
27e9893
refactor: fix names of things that were changed with search-and-repla…
algebraic-dev Sep 2, 2024
8d23eb0
fix: name of the localPath that is wrong
algebraic-dev Sep 2, 2024
b84a0e2
style: changes all the lambdas for fun
algebraic-dev Sep 2, 2024
3031f26
fix: wrong name of function
algebraic-dev Sep 2, 2024
16b4a72
fix: function names, ofOrdinal and others
algebraic-dev Sep 2, 2024
c772bd7
Merge branch 'master' of github.com:algebraic-dev/lean4
algebraic-dev Sep 2, 2024
cab1802
reafactor: notation and format
algebraic-dev Sep 20, 2024
d152573
fix: set functions and hour marker
algebraic-dev Sep 20, 2024
c6659e9
Merge branch 'master' of github.com:leanprover/lean4
algebraic-dev Sep 20, 2024
594aa87
fix: deprecations
algebraic-dev Sep 20, 2024
5367936
feat: remove lean parser from notation
algebraic-dev Sep 20, 2024
18feda1
fix: rename div to tdiv
algebraic-dev Sep 20, 2024
b213fc7
fix: tests
algebraic-dev Sep 20, 2024
9e74aac
fix: a bunch of comments and inlines
algebraic-dev Sep 26, 2024
fb8f037
fix: grammar correction
algebraic-dev Sep 30, 2024
d353fa6
feat: add leap second parser
algebraic-dev Oct 11, 2024
cc59eeb
fix: a lot of comment fixes and format change
algebraic-dev Oct 14, 2024
e8c48f4
feat: icu.h for timezone support on windows
algebraic-dev Oct 15, 2024
facbda1
fix: a bunch of fixes on comments and io
algebraic-dev Oct 17, 2024
0dd6c26
feat: wip refactor of zoneddatetime
algebraic-dev Oct 23, 2024
25c4aab
fix: remove dbg_trace
algebraic-dev Oct 23, 2024
e80379e
Merge branch 'master' of github.com:leanprover/lean4
algebraic-dev Oct 23, 2024
26adc20
feat: wip c++ next_transition
algebraic-dev Oct 23, 2024
fcef2e0
feat: add getZoneRules
algebraic-dev Oct 23, 2024
aa02d6e
feat: finish get next transition
algebraic-dev Oct 23, 2024
70c8225
fix: a bunch of stuff
algebraic-dev Oct 28, 2024
6086487
fix: comments and remove leap file
algebraic-dev Oct 28, 2024
946aff6
fix: nix test
algebraic-dev Oct 28, 2024
81b7035
fix: multiple fixes
algebraic-dev Oct 29, 2024
6c7ad97
feat: add functions that are lacking, fix other names
algebraic-dev Oct 31, 2024
646c8d3
fix: some functions and tests
algebraic-dev Oct 31, 2024
b2fc40a
fix: tests in tzif parse
algebraic-dev Oct 31, 2024
c2392aa
fix: memory leak in getZoneRules and tests
algebraic-dev Nov 1, 2024
bb24597
chore: small fixes in the documentation
algebraic-dev Nov 1, 2024
13bd578
fix: nix ci
algebraic-dev Nov 4, 2024
596588d
fix: trying to add nix ci again
algebraic-dev Nov 4, 2024
0fef367
Update src/Std/Time/DateTime/PlainDateTime.lean
algebraic-dev Nov 6, 2024
35c014a
feat: all the functions in the sheet
algebraic-dev Nov 6, 2024
d6e2024
fix: problem with index in the timezone
algebraic-dev Nov 6, 2024
6203f4b
Merge branch 'master' of github.com:algebraic-dev/lean4
algebraic-dev Nov 6, 2024
9ed4dc1
feat: add all the arithmetic operations between offsets
algebraic-dev Nov 6, 2024
8ec73c2
fix: nix ci
algebraic-dev Nov 6, 2024
1fc1f00
Merge branch 'master' of github.com:leanprover/lean4
algebraic-dev Nov 6, 2024
a69dca1
fix: problems with int64
algebraic-dev Nov 6, 2024
5b7a8fd
Update src/Std/Time.lean
algebraic-dev Nov 7, 2024
0236e9a
Update src/Std/Time.lean
algebraic-dev Nov 8, 2024
3feda98
fix: all the comments
algebraic-dev Nov 8, 2024
ca6062b
Merge branch 'master' of github.com:leanprover/lean4
algebraic-dev Nov 8, 2024
cdf692b
Merge branch 'master' of github.com:algebraic-dev/lean4
algebraic-dev Nov 8, 2024
0ddca8c
fix: docs
algebraic-dev Nov 8, 2024
14a193f
fix: windows time
algebraic-dev Nov 8, 2024
12cc801
feat: all the datetime functions
algebraic-dev Nov 8, 2024
9b34212
fix: docs
algebraic-dev Nov 8, 2024
a41a8c4
fix: two tests
algebraic-dev Nov 8, 2024
68a12ac
feat: add better empty transitions error
algebraic-dev Nov 8, 2024
74e63c0
fix: timeIO test
algebraic-dev Nov 8, 2024
8158cf9
fix: tz on windows
algebraic-dev Nov 8, 2024
bd8934b
Merge branch 'master' of https://github.com/leanprover/lean4
algebraic-dev Nov 8, 2024
70c1f0f
fix: RFC 8536 states that it theres no transition the index 0 of the …
algebraic-dev Nov 11, 2024
2ca4e23
Merge branch 'master' of github.com:algebraic-dev/lean4
algebraic-dev Nov 11, 2024
4f6b2cd
fix: timezone on windows
algebraic-dev Nov 11, 2024
0f6a930
test: add test
algebraic-dev Nov 11, 2024
89c672c
Merge branch 'master' of github.com:leanprover/lean4
algebraic-dev Nov 11, 2024
08310f0
fix: test for tzif
algebraic-dev Nov 12, 2024
7c60f50
fix: a bunch of small fixes and a huge test
algebraic-dev Nov 12, 2024
50a1756
feat: more tests
algebraic-dev Nov 12, 2024
97e312d
fix: nix ci
algebraic-dev Nov 12, 2024
2a30e1e
fix: remove mul/div instances for unitval and fix 2038 bug
algebraic-dev Nov 13, 2024
d5093c2
fix: u_failure check
algebraic-dev Nov 13, 2024
d488229
fix: some formats and parser that was not parsing more than the numbe…
algebraic-dev Nov 13, 2024
d499c8e
fix: proofs on months and removed Lean.Data.Rat from Lean.Dat
algebraic-dev Nov 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nix/bootstrap.nix
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ lib.warn "The Nix-based build is deprecated" rec {
ln -sf ${lean-all}/* .
'';
buildPhase = ''
ctest --output-junit test-results.xml --output-on-failure -E 'leancomptest_(doc_example|foreign)|leanlaketest_reverse-ffi' -j$NIX_BUILD_CORES
ctest --output-junit test-results.xml --output-on-failure -E 'leancomptest_(doc_example|foreign)|leanlaketest_reverse-ffi|leanruntest_timeIO' -j$NIX_BUILD_CORES
'';
installPhase = ''
mkdir $out
Expand Down
1 change: 0 additions & 1 deletion src/Lean/Data.lean
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@ import Lean.Data.Xml
import Lean.Data.NameTrie
import Lean.Data.RBTree
import Lean.Data.RBMap
import Lean.Data.Rat
import Lean.Data.RArray
3 changes: 2 additions & 1 deletion src/Lean/Meta/Tactic/LinearArith/Solver.lean
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ Authors: Leonardo de Moura
prelude
import Init.Data.Ord
import Init.Data.Array.DecidableEq
import Lean.Data.Rat
import Std.Internal.Rat

namespace Lean.Meta.Linear
open Std.Internal

structure Var where
id : Nat
Expand Down
1 change: 1 addition & 0 deletions src/Std.lean
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ Authors: Sebastian Ullrich
prelude
import Std.Data
import Std.Sat
import Std.Time
import Std.Tactic
import Std.Internal
6 changes: 4 additions & 2 deletions src/Lean/Data/Rat.lean → src/Std/Internal/Rat.lean
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import Init.NotationExtra
import Init.Data.ToString.Macro
import Init.Data.Int.DivMod
import Init.Data.Nat.Gcd
namespace Lean
namespace Std
namespace Internal

/-!
Rational numbers for implementing decision procedures.
Expand Down Expand Up @@ -144,4 +145,5 @@ instance : Coe Int Rat where
coe num := { num }

end Rat
end Lean
end Internal
end Std
231 changes: 231 additions & 0 deletions src/Std/Time.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
/-
algebraic-dev marked this conversation as resolved.
Show resolved Hide resolved
Copyright (c) 2024 Lean FRO, LLC. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sofia Rodrigues
-/
algebraic-dev marked this conversation as resolved.
Show resolved Hide resolved
prelude
import Std.Time.Time
import Std.Time.Date
import Std.Time.Zoned
import Std.Time.Format
import Std.Time.DateTime
import Std.Time.Notation
import Std.Time.Duration
import Std.Time.Zoned.Database

namespace Std
namespace Time

/-!
# Time
algebraic-dev marked this conversation as resolved.
Show resolved Hide resolved

The Lean API for date, time, and duration functionalities.
algebraic-dev marked this conversation as resolved.
Show resolved Hide resolved

# Overview

This module of the standard library defines various concepts related to time, such as dates, times,
time zones and durations. These types are designed to be strongly-typed and to avoid problems with
conversion. It offers both unbounded and bounded variants to suit different use cases, like
adding days to a date or representing ordinal values.

# Date and Time Components

Date and time components are classified into different types based how you SHOULD use them. These
components are categorized as:

## Offset
algebraic-dev marked this conversation as resolved.
Show resolved Hide resolved

Offsets represent unbounded shifts in specific date or time units. They are typically used in operations
like `date.addDays` where a `Day.Offset` is the parameter. Some offsets, such as `Month.Offset`, do not
correspond directly to a specific duration in seconds, as their value depends on the context (if
the year is leap or the size of the month). Offsets with a clear correspondent to seconds can be
converted because they use an internal type called `UnitVal`.

- Types with a correspondence to seconds:
- `Day.Offset`
- `Hour.Offset`
- `Week.Offset`
- `Millisecond.Offset`
- `Nanosecond.Offset`
- `Second.Offset`

- Types without a correspondence to seconds:
- `Month.Offset`
- `Year.Offset`

## Ordinal

Ordinal types represent specific bounded values in reference to another unit, e.g., `Day.Ordinal`
represents a day in a month, ranging from 1 to 31. Some ordinal types like `Hour.Ordinal` and `Second.Ordinal`,
allow for values beyond the normal range (e.g, 60 seconds) to accommodate special cases with leap seconds
like `23:59:60` that is valid in ISO 8601.

- Ordinal types:
- `Day.Ordinal`: Ranges from 1 to 31.
- `Day.Ordinal.OfYear`: Ranges from 1 to (365 or 366).
- `Month.Ordinal`: Ranges from 1 to 12.
- `WeekOfYear.Ordinal`: Ranges from 1 to 53.
- `Hour.Ordinal`: Ranges from 0 to 23.
- `Millisecond.Ordinal`: Ranges from 0 to 999.
- `Minute.Ordinal`: Ranges from 0 to 59.
- `Nanosecond.Ordinal`: Ranges from 0 to 999,999,999.
- `Second.Ordinal`: Ranges from 0 to 60.
- `Weekday`: That is a inductive type with all the seven days.

## Span

Span types are used as subcomponents of other types. They represent a range of values in the limits
of the parent type, e.g, `Nanosecond.Span` ranges from -999,999,999 to 999,999,999, as 1,000,000,000
nanoseconds corresponds to one second.

- Span types:
- `Nanosecond.Span`: Ranges from -999,999,999 to 999,999,999.

# Date and Time Types

Dates and times are made up of different parts. An `Ordinal` is an absolute value, like a specific day in a month,
while an `Offset` is a shift forward or backward in time, used in arithmetic operations to add or subtract days, months or years.
Dates use components like `Year.Ordinal`, `Month.Ordinal`, and `Day.Ordinal` to ensure they represent
valid points in time.

Some types, like `Duration`, include a `Span` to represent ranges over other types, such as `Second.Offset`.
This type can have a fractional nanosecond part that can be negative or positive that is represented as a `Nanosecond.Span`.

## Date
These types provide precision down to the day level, useful for representing and manipulating dates.

- **`PlainDate`:** Represents a calendar date in the format `YYYY-MM-DD`.

## Time
These types offer precision down to the nanosecond level, useful for representing and manipulating time of day.

- **`PlainTime`**: Represents a time of day in the format `HH:mm:ss,sssssssss`.

## Date and time
Combines date and time into a single representation, useful for precise timestamps and scheduling.

- **`PlainDateTime`**: Represents both date and time in the format `YYYY-MM-DDTHH:mm:ss,sssssssss`.
- **`Timestamp`**: Represents a specific point in time with nanosecond precision. Its zero value corresponds
to the UNIX epoch. This type should be used when sending or receiving timestamps between systems.

## Zoned date and times.
Combines date, time and time zones.

- **`DateTime`**: Represents both date and time but with a time zone in the type constructor.
- **`ZonedDateTime`**: Is a way to represent date and time that includes `ZoneRules`, which consider
Daylight Saving Time (DST). This means it can handle local time changes throughout the year better
than a regular `DateTime`. If you want to use a specific time zone without worrying about DST, you can
use the `ofTimestampWithZone` function, which gives you a `ZonedDateTime` based only on that time zone,
without considering the zone rules, otherwise you can use `ofTimestamp` or `ofTimestampWithIdentifier`.

## Duration
Represents spans of time and the difference between two points in time.

- **`Duration`**: Represents the time span or difference between two `Timestamp`s values with nanosecond precision.

# Formats

Format strings are used to convert between `String` representations and date/time types, like `yyyy-MM-dd'T'HH:mm:ss.sssZ`.
The table below shows the available format specifiers. Some specifiers can be repeated to control truncation or offsets.
When a character is repeated `n` times, it usually truncates the value to `n` characters.

The supported formats include:
- `G`: Represents the era, such as AD (Anno Domini) or BC (Before Christ).
- `G`, `GG`, `GGG` (short): Displays the era in a short format (e.g., "AD").
- `GGGG` (full): Displays the era in a full format (e.g., "Anno Domini").
- `GGGGG` (narrow): Displays the era in a narrow format (e.g., "A").
- `y`: Represents the year of the era.
algebraic-dev marked this conversation as resolved.
Show resolved Hide resolved
algebraic-dev marked this conversation as resolved.
Show resolved Hide resolved
- `yy`: Displays the year in a two-digit format, showing the last two digits (e.g., "04" for 2004).
- `yyyy`: Displays the year in a four-digit format (e.g., "2004").
- `yyyy+`: Extended format for years with more than four digits.
- `u`: Represents the year.
- `uu`: Two-digit year format, showing the last two digits (e.g., "04" for 2004).
- `uuuu`: Displays the year in a four-digit format (e.g., "2004" or "-1000").
- `uuuu+`: Extended format for handling years with more than four digits (e.g., "12345" or "-12345"). Useful for historical dates far into the past or future!
- `D`: Represents the day of the year.
- `M`: Represents the month of the year, displayed as either a number or text.
- `M`, `MM`: Displays the month as a number, with `MM` zero-padded (e.g., "7" for July, "07" for July with padding).
- `MMM`: Displays the abbreviated month name (e.g., "Jul").
- `MMMM`: Displays the full month name (e.g., "July").
- `MMMMM`: Displays the month in a narrow form (e.g., "J" for July).
- `d`: Represents the day of the month.
- `Q`: Represents the quarter of the year.
- `Q`, `QQ`: Displays the quarter as a number (e.g., "3", "03").
- `QQQ` (short): Displays the quarter as an abbreviated text (e.g., "Q3").
- `QQQQ` (full): Displays the full quarter text (e.g., "3rd quarter").
- `QQQQQ` (narrow): Displays the quarter as a short number (e.g., "3").
- `w`: Represents the week of the week-based year, each week starts on Monday (e.g., "27").
- `W`: Represents the week of the month, each week starts on Monday (e.g., "4").
- `E`: Represents the day of the week as text.
- `E`, `EE`, `EEE`: Displays the abbreviated weekday name (e.g., "Tue").
- `EEEE`: Displays the full day name (e.g., "Tuesday").
- `EEEEE`: Displays the narrow day name (e.g., "T" for Tuesday).
- `e`: Represents the weekday as number or text.
- `e`, `ee`: Displays the the as a number, starting from 1 (Monday) to 7 (Sunday).
- `eee`, `eeee`, `eeeee`: Displays the weekday as text (same format as `E`).
- `F`: Represents the week of the month that the first week starts on the first day of the month (e.g., "3").
- `a`: Represents the AM or PM designation of the day.
- `a`, `aa`, `aaa`: Displays AM or PM in a concise format (e.g., "PM").
- `aaaa`: Displays the full AM/PM designation (e.g., "Post Meridium").
- `h`: Represents the hour of the AM/PM clock (1-12) (e.g., "12").
- One or more repetitions of the character indicates the truncation of the value to the specified number of characters.
- `K`: Represents the hour of the AM/PM clock (0-11) (e.g., "0").
- One or more repetitions of the character indicates the truncation of the value to the specified number of characters.
- `k`: Represents the hour of the day in a 1-24 format (e.g., "24").
- One or more repetitions of the character indicates the truncation of the value to the specified number of characters.
- `H`: Represents the hour of the day in a 0-23 format (e.g., "0").
- One or more repetitions of the character indicates the truncation of the value to the specified number of characters.
- `m`: Represents the minute of the hour (e.g., "30").
- One or more repetitions of the character indicates the truncation of the value to the specified number of characters.
- `s`: Represents the second of the minute (e.g., "55").
- One or more repetitions of the character indicates the truncation of the value to the specified number of characters.
- `S`: Represents a fraction of a second, typically displayed as a decimal number (e.g., "978" for milliseconds).
- One or more repetitions of the character indicates the truncation of the value to the specified number of characters.
- `A`: Represents the millisecond of the day (e.g., "1234").
- One or more repetitions of the character indicates the truncation of the value to the specified number of characters.
- `n`: Represents the nanosecond of the second (e.g., "987654321").
- One or more repetitions of the character indicates the truncation of the value to the specified number of characters.
- `N`: Represents the nanosecond of the day (e.g., "1234000000").
- One or more repetitions of the character indicates the truncation of the value to the specified number of characters.
- `VV`: Represents the time zone ID, which could be a city-based zone (e.g., "America/Los_Angeles"), a UTC marker (`"Z"`), or a specific offset (e.g., "-08:30").
- One or more repetitions of the character indicates the truncation of the value to the specified number of characters.
- `z`: Represents the time zone name.
- `z`, `zz`, `zzz`: Shows an abbreviated time zone name (e.g., "PST" for Pacific Standard Time).
- `zzzz`: Displays the full time zone name (e.g., "Pacific Standard Time").
- `O`: Represents the localized zone offset in the format "GMT" followed by the time difference from UTC.
- `O`: Displays the GMT offset in a simple format (e.g., "GMT+8").
- `OOOO`: Displays the full GMT offset, including hours and minutes (e.g., "GMT+08:00").
- `X`: Represents the zone offset. It uses 'Z' for UTC and can represent any offset (positive or negative).
- `X`: Displays the hour offset (e.g., "-08").
- `XX`: Displays the hour and minute offset without a colon (e.g., "-0830").
- `XXX`: Displays the hour and minute offset with a colon (e.g., "-08:30").
- `XXXX`: Displays the hour, minute, and second offset without a colon (e.g., "-083045").
- `XXXXX`: Displays the hour, minute, and second offset with a colon (e.g., "-08:30:45").
- `x`: Represents the zone offset. Similar to X, but does not display 'Z' for UTC and focuses only on positive offsets.
- `x`: Displays the hour offset (e.g., "+08").
- `xx`: Displays the hour and minute offset without a colon (e.g., "+0830").
- `xxx`: Displays the hour and minute offset with a colon (e.g., "+08:30").
- `xxxx`: Displays the hour, minute, and second offset without a colon (e.g., "+083045").
- `xxxxx`: Displays the hour, minute, and second offset with a colon (e.g., "+08:30:45").
- `Z`: Always includes an hour and minute offset and may use 'Z' for UTC, providing clear differentiation between UTC and other time zones.
- `Z`: Displays the hour and minute offset without a colon (e.g., "+0800").
- `ZZ`: Displays "GMT" followed by the time offset (e.g., "GMT+08:00" or "Z").
- `ZZZ`: Displays the full hour, minute, and second offset with a colon (e.g., "+08:30:45" or "Z").

# Macros

In order to help the user build dates easily, there are a lot of macros available for creating dates.
The `.sssssssss` can be ommited in most cases.


- **`date("uuuu-MM-dd")`**: Represents a date in the `uuuu-MM-dd` format, where `uuuu` refers to the year.
- **`time("HH:mm:ss.sssssssss")`**: Represents a time in the format `HH:mm:ss.sssssssss`, including optional support for nanoseconds.
- **`datetime("uuuu-MM-ddTHH:mm:ss.sssssssss")`**: Represents a datetime value in the `uuuu-MM-ddTHH:mm:ss.sssssssss` format, with optional nanoseconds.
- **`offset("+HH:mm")`**: Represents a timezone offset in the format `+HH:mm`, where `+` or `-` indicates the direction from UTC.
- **`timezone("NAME/ID ZZZ")`**: Specifies a timezone using a region-based name or ID, along with its associated offset.
- **`datespec("FORMAT")`**: Defines a compile-time date format based on the provided string.
- **`zoned("uuuu-MM-ddTHH:mm:ss.sssssssssZZZ")`**: Represents a `ZonedDateTime` with a fixed timezone and optional nanosecond precision.
- **`zoned("uuuu-MM-ddTHH:mm:ss.sssssssss[IDENTIFIER]")`**: Defines an `IO ZonedDateTime`, where the timezone identifier is dynamically retrieved from the default timezone database.
- **`zoned("uuuu-MM-ddTHH:mm:ss.sssssssss, timezone")`**: Represents an `IO ZonedDateTime`, using a specified `timezone` term and allowing optional nanoseconds.

-/
8 changes: 8 additions & 0 deletions src/Std/Time/Date.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/-
Copyright (c) 2024 Lean FRO, LLC. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sofia Rodrigues
-/
prelude
import Std.Time.Date.Basic
import Std.Time.Date.PlainDate
Loading
Loading