-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add ITime, an integer time type #124
Open
Sbozzolo
wants to merge
2
commits into
main
Choose a base branch
from
gb/timetype
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains 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
Sbozzolo
force-pushed
the
gb/timetype
branch
2 times, most recently
from
November 6, 2024 22:37
000b68b
to
2b19e4b
Compare
This commit introduces the `ITime` type, a new approach to handling time and dates within CliMA simulations. `ITime` utilizes integer-based representation and operations, offering three advantages: - Eliminates floating-point errors. - Provides a trivial way to go from times to dates. - Provides an abstraction layer over the calendar system, enabling future support for calendars beyond the Gregorian calendar currently used by Dates. `ITime` is defined by a `counter`, a `period`, and an optional `start_date`. The counter tracks the number of elapsed periods since the start date and the period is customizable (1 second by default). `ITime`s also support fractional counters (currently represented by `Rational`s) to account for stages in the timestepper loop. `ITime`s support the arithmetic operations (+, -, *, /, div) while maintaining consistency in the units and the start date. This allows users to just specify `start_date` and `period` for one of their `ITime`s (e.g., `t_start`), and everything will be automatically propagated. Given an `ITime` `t`, one can obtain its time with `seconds(t)` and the date with `date(t)`. I also added `float(t)` to help with the transition.
glwagner
reviewed
Nov 20, 2024
""" | ||
struct ITime{ | ||
INT <: IntegerOrRatio, | ||
DT <: Dates.FixedPeriod, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested change
DT <: Dates.FixedPeriod, | |
DT <: Union{Number, Dates.FixedPeriod}, |
glwagner
reviewed
Nov 20, 2024
} | ||
counter::INT | ||
period::DT | ||
start_date::START_DATE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested change
start_date::START_DATE | |
epoch::START_DATE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This commit introduces the
ITime
type, a new approach to handling time and dates within CliMA simulations.ITime
utilizes integer-based representation and operations, offering three advantages:ITime
is defined by acounter
, aperiod
, and an optionalstart_date
. The counter tracks the number of elapsed periods since the start date and the period is customizable (1 second by default).ITime
s also support fractional counters (currently represented byRational
s) to account for stages in the timestepper loop.ITime
s support the arithmetic operations (+, -, *, /, div) while maintaining consistency in the units and the start date. This allows users to just specifystart_date
andperiod
for one of theirITime
s (e.g.,t_start
), and everything will be automatically propagated.Given an
ITime
t
, one can obtain its time withseconds(t)
and the date withdate(t)
. I also addedfloat(t)
to help with the transition.