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

Add ITime, an integer time type #124

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Add ITime, an integer time type #124

wants to merge 2 commits into from

Conversation

Sbozzolo
Copy link
Member

@Sbozzolo Sbozzolo commented Nov 6, 2024

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). ITimes also support fractional counters (currently represented by Rationals) to account for stages in the timestepper loop.

ITimes 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 ITimes (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.

@Sbozzolo Sbozzolo force-pushed the gb/timetype branch 2 times, most recently from 000b68b to 2b19e4b Compare November 6, 2024 22:37
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.
"""
struct ITime{
INT <: IntegerOrRatio,
DT <: Dates.FixedPeriod,
Copy link
Member

@glwagner glwagner Nov 20, 2024

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},

}
counter::INT
period::DT
start_date::START_DATE
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
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants