Skip to content
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
8 changes: 4 additions & 4 deletions core/expression/src/vm/date/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,11 @@ mod helper {
}
DurationUnit::Year => {
let year = date_time.year();
let month = Month::try_from(date_time.month().to_u8()?).ok()?;
let month = Month::December;
let days_in_month = month.num_days(year)?.to_u32()?;

date_time
.with_month(12)?
.with_month(month.number_from_month())?
.with_day(days_in_month)?
.with_hour(23)?
.with_minute(59)?
Expand Down Expand Up @@ -411,8 +411,8 @@ mod helper {
pub fn is_after(a: DateTime<Tz>, b: DateTime<Tz>, unit: Option<DurationUnit>) -> Option<bool> {
match unit {
Some(unit) => {
let start_b = start_of(b, unit)?;
Some(a > start_b)
let start_a = start_of(a, unit)?;
Some(b < start_a)
}
None => Some(a > b),
}
Expand Down
26 changes: 26 additions & 0 deletions core/expression/tests/data/date.csv
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,32 @@ d('2023-10-15').isSameOrAfter(d('2023-10-15'));;true
d('2023-10-15').isSameOrAfter(d('2023-10-14'));;true
d('2023-10-15').isSameOrAfter(d('2023-10-16'));;false

d('2025-02-01').isAfter(d('2025-01-05'), 'year');;false
d('2025-02-01').isAfter(d('2024-12-31'), 'year');;true
d('2025-02-01').isBefore(d('2025-03-01'), 'year');;false
d('2025-02-01').isBefore(d('2026-01-01'), 'year');;true
d('2025-02-01').isSame(d('2025-12-31'), 'year');;true
d('2025-02-01').isSame(d('2026-01-01'), 'year');;false

d('2025-02-15').isAfter(d('2025-01-05'), 'month');;true
d('2025-02-15').isAfter(d('2025-02-05'), 'month');;false
d('2025-02-15').isBefore(d('2025-03-01'), 'month');;true
d('2025-02-15').isBefore(d('2025-02-28'), 'month');;false
d('2025-02-15').isSame(d('2025-02-28'), 'month');;true
d('2025-02-15').isSame(d('2025-03-01'), 'month');;false
d('2025-04-15').isAfter(d('2025-01-01'), 'quarter');;true
d('2025-02-15').isAfter(d('2025-03-31'), 'quarter');;false
d('2025-02-15').isBefore(d('2025-04-01'), 'quarter');;true
d('2025-02-15').isBefore(d('2025-03-31'), 'quarter');;false
d('2025-02-15').isSame(d('2025-03-15'), 'quarter');;true
d('2025-02-15').isSame(d('2025-04-01'), 'quarter');;false
d('2025-02-15').isAfter(d('2025-02-14'), 'day');;true
d('2025-02-15').isAfter(d('2025-02-15'), 'day');;false
d('2025-02-15').isBefore(d('2025-02-16'), 'day');;true
d('2025-02-15').isBefore(d('2025-02-15'), 'day');;false
d('2025-02-15').isSame(d('2025-02-15 12:00:00'), 'day');;true
d('2025-02-15').isSame(d('2025-02-16'), 'day');;false

# Date getters
d('2023-10-15').year();;2023
d('2023-10-15').month();;10
Expand Down
Loading