-
-
Notifications
You must be signed in to change notification settings - Fork 5
Basic time types #1
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
Merged
Changes from 5 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
f5309e7
Duration, timestamp
lpil 671b7d4
Date parse function
lpil 97de3c5
Duration constructors
lpil 9b3ce59
Make opaque
lpil d7abab4
Constructors and getters
lpil 2b07766
Implement some duration types
lpil d966072
duration.to_iso8601_string
lpil 1c4203c
Include nanoseconds in duration
lpil ce9f8e5
timestamp.duration
lpil 0dc9da1
Documentation
lpil 716c30f
Timestamp functions
lpil 14696d3
rfc3339
lpil 977ddf9
Run tests on JS also
lpil 719f847
Accept an offset in RFC function
lpil 01f0945
Test for Jak
lpil 92ed148
Fix duration normalise bug
lpil 9933ffc
Fix timestamp normalise bug
lpil c20b983
Compare properties
lpil 3bbdeb1
Better qcheck usage
lpil 490d46b
Adopt decided upon duration comparison semantics
lpil 6efb6e1
Work around qcheck bug
lpil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import gleam/order | ||
|
||
// TODO: document | ||
pub opaque type Duration { | ||
// When compiling to JavaScript ints have limited precision and size. This | ||
// means that if we were to store the the timestamp in a single int the | ||
// duration would not be able to represent very large or small durations. | ||
// Durations are instead represented as a number of seconds and a number of | ||
// nanoseconds. | ||
// | ||
// If you have manually adjusted the seconds and nanoseconds values the | ||
// `normalise` function can be used to ensure the time is represented the | ||
// intended way, with `nanoseconds` being positive and less than 1 second. | ||
Duration(seconds: Int, nanoseconds: Int) | ||
} | ||
|
||
// TODO: test | ||
/// Ensure the duration is represented with `nanoseconds` being positive and | ||
/// less than 1 second. | ||
/// | ||
/// This function does not change the amount of time that the duratoin refers | ||
/// to, it only adjusts the values used to represent the time. | ||
/// | ||
fn normalise(duration: Duration) -> Duration { | ||
todo | ||
} | ||
|
||
// TODO: docs | ||
// TODO: test | ||
pub fn compare(left: Duration, right: Duration) -> order.Order { | ||
todo | ||
} | ||
|
||
// TODO: docs | ||
// TODO: test | ||
pub fn difference(left: Duration, right: Duration) -> Duration { | ||
todo | ||
} | ||
|
||
// TODO: docs | ||
// TODO: test | ||
pub fn add(left: Duration, right: Duration) -> Duration { | ||
todo | ||
} | ||
|
||
// TODO: docs | ||
// TODO: test | ||
pub fn to_iso8601_string(duration: Duration) -> String { | ||
lpil marked this conversation as resolved.
Show resolved
Hide resolved
|
||
todo | ||
} | ||
|
||
// TODO: docs | ||
// TODO: test | ||
pub fn minutes(amount: Int) -> Duration { | ||
todo | ||
} | ||
|
||
// TODO: docs | ||
// TODO: test | ||
pub fn seconds(amount: Int) -> Duration { | ||
todo | ||
} | ||
|
||
// TODO: docs | ||
// TODO: test | ||
pub fn milliseconds(amount: Int) -> Duration { | ||
todo | ||
} | ||
|
||
// TODO: docs | ||
// TODO: test | ||
pub fn nanoseconds(amount: Int) -> Duration { | ||
todo | ||
} | ||
|
||
// TODO: docs | ||
// TODO: test | ||
pub fn to_seconds(duration: Duration) -> Float { | ||
todo | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import gleam/order | ||
import gleam/time/duration.{type Duration} | ||
|
||
/// A timestamp represents a moment in time, represented as an amount of time | ||
/// since 00:00:00 UTC on 1 January 1970, also known as the _Unix epoch_. | ||
/// | ||
/// # Wall clock time and monotonicity | ||
/// | ||
/// Time is very complicated, especially on computers! While they generally do | ||
/// a good job of keeping track of what the time is, computers can get | ||
/// out-of-sync and start to report a time that is too late or too early. Most | ||
/// computers use "network time protocol" to tell each other what they think | ||
/// the time is, and computers that realise they are running too fast or too | ||
/// slow will adjust their clock to correct it. When this happens it can seem | ||
/// to your program that the current time has changed, and it may have even | ||
/// jumped backwards in time! | ||
/// | ||
/// This measure of time is called _wall clock time_, and it is what people | ||
/// commonly think of when they think of time. It is important to be aware that | ||
/// it can go backwards, and your program must not rely on it only ever going | ||
/// forwards at a steady rate. For example, for tracking what order events happen | ||
/// in. | ||
/// | ||
/// This module uses wall clock time. If your program needs time values to always | ||
/// increase you will need a _monotonic_ time instead. | ||
/// | ||
/// The exact way that time works will depend on what runtime you use. The | ||
/// Erlang documentation on time has a lot of detail about time generally as well | ||
/// as how it works on the BEAM, it is worth reading. | ||
/// <https://www.erlang.org/doc/apps/erts/time_correction>. | ||
/// | ||
/// # Converting to local time | ||
/// | ||
/// Timestamps don't take into account time zones, so a moment in time will | ||
/// have the same timestamp value regardless of where you are in the world. To | ||
/// convert them to local time you will need to know details about the local | ||
/// time zone, likely from a time zone database. | ||
/// | ||
/// The UTC time zone never has any adjustments, so you don't need a time zone | ||
/// database to convert to UTC local time. | ||
/// | ||
pub opaque type Timestamp { | ||
lpil marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// When compiling to JavaScript ints have limited precision and size. This | ||
// means that if we were to store the the timestamp in a single int the | ||
// timestamp would not be able to represent times far in the future or in the | ||
// past, or distinguish between two times that are close together. Timestamps | ||
// are instead represented as a number of seconds and a number of nanoseconds. | ||
// | ||
// If you have manually adjusted the seconds and nanoseconds values the | ||
// `normalise` function can be used to ensure the time is represented the | ||
// intended way, with `nanoseconds` being positive and less than 1 second. | ||
Timestamp(seconds: Int, nanoseconds: Int) | ||
} | ||
|
||
// TODO: test | ||
/// Ensure the time is represented with `nanoseconds` being positive and less | ||
/// than 1 second. | ||
/// | ||
/// This function does not change the time that the timestamp refers to, it | ||
/// only adjusts the values used to represent the time. | ||
lpil marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// | ||
fn normalise(timestamp: Timestamp) -> Timestamp { | ||
todo | ||
} | ||
|
||
// TODO: docs | ||
// TODO: test | ||
pub fn compare(left: Timestamp, right: Timestamp) -> order.Order { | ||
todo | ||
} | ||
|
||
// TODO: docs | ||
// TODO: test | ||
pub fn now() -> Timestamp { | ||
todo | ||
} | ||
|
||
// TODO: docs | ||
// TODO: test | ||
pub fn difference(left: Timestamp, right: Timestamp) -> Duration { | ||
todo | ||
} | ||
|
||
// TODO: docs | ||
// TODO: test | ||
pub fn add(timetamp: Timestamp, duration: Duration) -> Duration { | ||
todo | ||
} | ||
|
||
// TODO: docs | ||
// TODO: test | ||
pub fn to_rfc3339_utc_string(timestamp: Timestamp) -> String { | ||
todo | ||
} | ||
|
||
// TODO: docs | ||
// TODO: test | ||
pub fn parse_rfc3339(input: String) -> Result(Timestamp, Nil) { | ||
todo | ||
} | ||
|
||
// TODO: docs | ||
// TODO: test | ||
pub fn from_unix_seconds(seconds: Int) -> Timestamp { | ||
todo | ||
} | ||
|
||
// TODO: docs | ||
// TODO: test | ||
pub fn from_unix_seconds_and_nanoseconds( | ||
seconds seconds: Int, | ||
nanoseconds nanoseconds: Int, | ||
) -> Timestamp { | ||
todo | ||
} | ||
|
||
// TODO: docs | ||
// TODO: test | ||
pub fn to_unix_seconds(input: String) -> Float { | ||
todo | ||
} | ||
|
||
// TODO: docs | ||
// TODO: test | ||
pub fn to_unix_seconds_and_nanoseconds(input: String) -> #(Int, Int) { | ||
todo | ||
} |
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.