computer: fix coarse lazy indexes

This commit is contained in:
nym21
2025-07-11 01:51:04 +02:00
parent 029a85081b
commit 4489920cbf
33 changed files with 785 additions and 74 deletions

View File

@@ -115,7 +115,7 @@ impl FromCoarserIndex<WeekIndex> for DateIndex {
} else if coarser == 1 {
1
} else {
4 + (coarser - 1) * 7
4 + (coarser - 2) * 7
}
}
@@ -126,7 +126,7 @@ impl FromCoarserIndex<WeekIndex> for DateIndex {
} else if coarser == 1 {
3
} else {
3 + coarser * 7
3 + (coarser - 1) * 7
}
}
}

View File

@@ -1,4 +1,7 @@
use std::{fmt::Debug, ops::Add};
use std::{
fmt::Debug,
ops::{Add, AddAssign, Div},
};
use serde::{Deserialize, Serialize};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
@@ -63,6 +66,27 @@ impl Add<usize> for DecadeIndex {
}
}
impl Add<DecadeIndex> for DecadeIndex {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
Self::from(self.0 + rhs.0)
}
}
impl AddAssign for DecadeIndex {
fn add_assign(&mut self, rhs: Self) {
*self = Self(self.0 + rhs.0)
}
}
impl Div<usize> for DecadeIndex {
type Output = Self;
fn div(self, _: usize) -> Self::Output {
unreachable!()
}
}
impl From<DateIndex> for DecadeIndex {
fn from(value: DateIndex) -> Self {
Self::from(Date::from(value))

View File

@@ -1,4 +1,7 @@
use std::{fmt::Debug, ops::Add};
use std::{
fmt::Debug,
ops::{Add, AddAssign, Div},
};
use serde::{Deserialize, Serialize};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
@@ -57,6 +60,27 @@ impl Add<usize> for MonthIndex {
}
}
impl Add<MonthIndex> for MonthIndex {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
Self::from(self.0 + rhs.0)
}
}
impl AddAssign for MonthIndex {
fn add_assign(&mut self, rhs: Self) {
*self = Self(self.0 + rhs.0)
}
}
impl Div<usize> for MonthIndex {
type Output = Self;
fn div(self, _: usize) -> Self::Output {
unreachable!()
}
}
impl From<DateIndex> for MonthIndex {
fn from(value: DateIndex) -> Self {
Self::from(Date::from(value))

View File

@@ -1,4 +1,7 @@
use std::{fmt::Debug, ops::Add};
use std::{
fmt::Debug,
ops::{Add, AddAssign, Div},
};
use serde::{Deserialize, Serialize};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
@@ -57,6 +60,27 @@ impl Add<usize> for QuarterIndex {
}
}
impl Add<QuarterIndex> for QuarterIndex {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
Self::from(self.0 + rhs.0)
}
}
impl AddAssign for QuarterIndex {
fn add_assign(&mut self, rhs: Self) {
*self = Self(self.0 + rhs.0)
}
}
impl Div<usize> for QuarterIndex {
type Output = Self;
fn div(self, _: usize) -> Self::Output {
unreachable!()
}
}
impl From<MonthIndex> for QuarterIndex {
fn from(value: MonthIndex) -> Self {
Self((usize::from(value) / 3) as u16)

View File

@@ -1,4 +1,7 @@
use std::{fmt::Debug, ops::Add};
use std::{
fmt::Debug,
ops::{Add, AddAssign, Div},
};
use serde::{Deserialize, Serialize};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
@@ -57,6 +60,27 @@ impl Add<usize> for SemesterIndex {
}
}
impl Add<SemesterIndex> for SemesterIndex {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
Self::from(self.0 + rhs.0)
}
}
impl AddAssign for SemesterIndex {
fn add_assign(&mut self, rhs: Self) {
*self = Self(self.0 + rhs.0)
}
}
impl Div<usize> for SemesterIndex {
type Output = Self;
fn div(self, _: usize) -> Self::Output {
unreachable!()
}
}
impl From<MonthIndex> for SemesterIndex {
fn from(value: MonthIndex) -> Self {
Self((usize::from(value) / 6) as u16)

View File

@@ -1,4 +1,7 @@
use std::{fmt::Debug, ops::Add};
use std::{
fmt::Debug,
ops::{Add, AddAssign, Div},
};
use serde::{Deserialize, Serialize};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
@@ -49,6 +52,27 @@ impl From<WeekIndex> for usize {
}
}
impl Add<WeekIndex> for WeekIndex {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
Self::from(self.0 + rhs.0)
}
}
impl AddAssign for WeekIndex {
fn add_assign(&mut self, rhs: Self) {
*self = Self(self.0 + rhs.0)
}
}
impl Div<usize> for WeekIndex {
type Output = Self;
fn div(self, _: usize) -> Self::Output {
unreachable!()
}
}
impl Add<usize> for WeekIndex {
type Output = Self;

View File

@@ -1,4 +1,7 @@
use std::{fmt::Debug, ops::Add};
use std::{
fmt::Debug,
ops::{Add, AddAssign, Div},
};
use serde::{Deserialize, Serialize};
use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
@@ -51,6 +54,27 @@ impl Add<usize> for YearIndex {
}
}
impl Add<YearIndex> for YearIndex {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
Self::from(self.0 + rhs.0)
}
}
impl AddAssign for YearIndex {
fn add_assign(&mut self, rhs: Self) {
*self = Self(self.0 + rhs.0)
}
}
impl Div<usize> for YearIndex {
type Output = Self;
fn div(self, _: usize) -> Self::Output {
unreachable!()
}
}
impl From<DateIndex> for YearIndex {
fn from(value: DateIndex) -> Self {
Self::from(Date::from(value))