Compare commits

..

1 Commits

Author SHA1 Message Date
Thea Schöbl
927f847e5c feat: email client prototype 2024-11-04 16:46:53 +00:00
2 changed files with 2 additions and 8 deletions

View File

@@ -1,6 +1,6 @@
import {Pipe, PipeTransform} from '@angular/core';
import {SCRange, isInRange, SCISO8601DateRange} from '@openstapps/core';
import {NormalizedInterval, differenceInMilliseconds, interval} from 'date-fns';
import {NormalizedInterval, differenceInMilliseconds, interval, isEqual} from 'date-fns';
import {EMPTY, Observable, SchedulerLike, asyncScheduler, concat, defer, map, of, timer} from 'rxjs';
@Pipe({
@@ -16,8 +16,6 @@ export class InRangePipe implements PipeTransform {
export const MIN_DATE = new Date(0);
export const MAX_DATE = new Date(1e15);
// Maximum safe delay for JavaScript timers (~24.8 days)
export const MAX_DELAY = 2 ** 31 - 1;
@Pipe({
name: 'rangeToDateInterval',
@@ -45,7 +43,7 @@ export function isWithinIntervalObservable(
return concat(
of(activate <= 0 && deactivate > 0),
activate <= 0 ? EMPTY : timer(value.start, scheduler).pipe(map(() => true)),
differenceInMilliseconds(value.end, now) >= MAX_DELAY || deactivate <= 0
isEqual(value.end, MAX_DATE) || deactivate <= 0
? EMPTY
: timer(value.end, scheduler).pipe(map(() => false)),
);

View File

@@ -1,7 +1,6 @@
import {TestScheduler} from 'rxjs/testing';
import {MAX_DATE, MIN_DATE, isWithinIntervalObservable} from './in-range.pipe';
import {interval} from 'date-fns';
import {MAX_DELAY} from './in-range.pipe';
/**
* Test macro
@@ -40,7 +39,4 @@ describe('isWithinIntervalObservable', () => {
test([500, 1000], '499ms ^', '499ms f t 499ms (f|)');
test([500, 1000], '^ 750ms !', 'f 499ms t');
// Long interval test case: emit `true` and then complete (EMPTY) because `end` is beyond the delay limit
test([500, 500 + MAX_DELAY + 2000], '1s ^', '1s (t|)');
});