Skip to content

Commit

Permalink
Merge pull request #73 from logicalmechanism/update-moment-type-3
Browse files Browse the repository at this point in the history
adding shift to moment
  • Loading branch information
logicalmechanism authored Jan 31, 2024
2 parents d30b8ed + 0a49999 commit be60aee
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
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

0 comments on commit be60aee

Please sign in to comment.