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

adding shift to moment #73

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# v0.x.y

- Added the `Wallets` type and `to_vks` to the wallet submodule.
- Added `get` and `version` to the cip68 types submodule.
- Added `get` and `version` to the cip68 submodule.
- Addded `shift` to the moment submodule.

# v0.4.4

Expand Down
27 changes: 27 additions & 0 deletions lib/assist/types/moment.ak
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,33 @@ pub type Moment {
pub type Moments =
List<Moment>

/// Shifts a moment by some integer amount. This is great for incrementing
/// a fixed moment of time, maybe like an epoch boundary by five days.
///
/// ```aiken
/// moment.shift(this_moment, a_day)
/// ```
pub fn shift(m: Moment, t: Int) -> Moment {
Moment { start: m.start + t, end: m.end + t }
}

test no_shift() {
let m: Moment = Moment { start: 0, end: 0 }
shift(m, 0) == m
}

test positive_shift() {
let m1: Moment = Moment { start: 1, end: 5 }
let m2: Moment = Moment { start: 11, end: 15 }
shift(m1, 10) == m2
}

test negative_shift() {
let m1: Moment = Moment { start: 11, end: 15 }
let m2: Moment = Moment { start: 1, end: 5 }
shift(m1, -10) == m2
}

/// Check if a moment data structure is logical.
///
/// ```aiken
Expand Down
Loading