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
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@
<div class="second-row">
@if (!showAccess || !item.ShareArchiveVO) {
<span>
{{ item.displayDT | prDate: item.TimezoneVO : 'date' }}
{{ startDisplayTime | prDate: item.TimezoneVO : 'date' }}
@if (item.dataStatus > 0) {
<span @ngIfFadeInAnimation>{{
item.displayDT | prDate: item.TimezoneVO : 'time'
startDisplayTime | prDate: item.TimezoneVO : 'time'
}}</span>
Comment on lines +93 to 97
}
</span>
Expand All @@ -112,12 +112,12 @@
<div class="date">
@if (item.dataStatus > 0) {
<div class="date-top" @ngIfFadeInAnimation>
{{ item.displayDT | prDate: item.TimezoneVO : 'date' }}
{{ startDisplayTime | prDate: item.TimezoneVO : 'date' }}
</div>
}
@if (item.dataStatus > 0) {
<div class="date-bottom" @ngIfFadeInAnimation>
{{ item.displayDT | prDate: item.TimezoneVO : 'time' }}
{{ startDisplayTime | prDate: item.TimezoneVO : 'time' }}
</div>
Comment on lines 118 to 121
}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class MockItemTypeIconPipe implements PipeTransform {

@Pipe({ name: 'prDate' })
export class MockPrDatePipe implements PipeTransform {
transform(value: any, format?: string): string {
return `mocked-date${format ? `-${format}` : ''}`;
transform(value: any, ...args: any[]): string {
return String(value ?? '');
}
}

Expand Down Expand Up @@ -342,4 +342,51 @@ describe('FileListItemComponent', () => {

expect(component.recordThumbnailUrl).toBe('https://example.com/thumb.jpg');
});

it('should display displayTime instead of displayDT when displayTime is set', () => {
component.item.displayTime = '2020-06-10';
component.item.displayDT = '2023-01-01T00:00:00.000Z';
fixture.detectChanges();

const secondRowDate =
fixture.nativeElement.querySelector('.second-row span')?.textContent;

expect(secondRowDate).toContain('2020-06-10');
expect(secondRowDate).not.toContain('2023-01-01');
});

it('should display displayDT when displayTime is not set', () => {
component.item.displayTime = undefined;
component.item.displayDT = '2023-01-01T00:00:00.000Z';
fixture.detectChanges();

const secondRowDate =
fixture.nativeElement.querySelector('.second-row span')?.textContent;

expect(secondRowDate).toContain('2023-01-01T00:00:00.000Z');
});

it('should display only the start date when displayTime is an EDTF interval', () => {
component.item.displayTime = '2020-06-10/2026-06-15';
component.item.displayDT = '2023-01-01T00:00:00.000Z';
fixture.detectChanges();

const secondRowDate =
fixture.nativeElement.querySelector('.second-row span')?.textContent;

expect(secondRowDate).toContain('2020-06-10');
expect(secondRowDate).not.toContain('2026-06-15');
expect(secondRowDate).not.toContain('2023-01-01');
});

it('should fall back to displayDT when the EDTF interval has an open start', () => {
component.item.displayTime = '../2026-06-15';
component.item.displayDT = '2023-01-01T00:00:00.000Z';
fixture.detectChanges();

const secondRowDate =
fixture.nativeElement.querySelector('.second-row span')?.textContent;

expect(secondRowDate).toContain('2023-01-01T00:00:00.000Z');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
} from '@root/app/models';
import { DataStatus } from '@models/data-status.enum';
import { EditService } from '@core/services/edit/edit.service';
import { EdtfService } from '@shared/services/edtf-service/edtf.service';
import {
RecordResponse,
FolderResponse,
Expand Down Expand Up @@ -247,8 +248,16 @@ export class FileListItemComponent
private storage: StorageService,
@Inject(DOCUMENT) private document: Document,
private shareLinksService: ShareLinksService,
private edtfService: EdtfService,
) {}

get startDisplayTime(): string {
return (
this.edtfService.getEdtfIntervalStartDate(this.item.displayTime) ||
this.item.displayDT
);
}

async ngOnInit() {
this.recordThumbnailUrl = GetThumbnail(this.item);
const date = new Date(this.item.displayDT);
Expand Down
56 changes: 56 additions & 0 deletions src/app/shared/pipes/pr-date.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,68 @@
import { TimezoneVOData } from '@models';
import { PrDatePipe } from './pr-date.pipe';

const cdtTimezone: TimezoneVOData = {
dstAbbrev: 'CDT',
dstOffset: '-05:00',
stdAbbrev: 'CST',
stdOffset: '-06:00',
};

describe('PrDatePipe', () => {
it('create an instance', () => {
const pipe = new PrDatePipe();

expect(pipe).toBeTruthy();
});

it('returns undefined for empty string', () => {
const pipe = new PrDatePipe();

expect(pipe.transform('')).toBeUndefined();
});

it('returns undefined for null', () => {
const pipe = new PrDatePipe();

expect(pipe.transform(null as any)).toBeUndefined();
});

describe('date-only strings (no T)', () => {
it('returns the date formatted from UTC', () => {
const pipe = new PrDatePipe();

expect(pipe.transform('2020-06-10')).toBe('2020-06-10');
});

it('returns the date when part is date', () => {
const pipe = new PrDatePipe();

expect(pipe.transform('2020-06-10', undefined, 'date')).toBe(
'2020-06-10',
);
});

it('returns undefined when part is time', () => {
const pipe = new PrDatePipe();

expect(pipe.transform('2020-06-10', undefined, 'time')).toBeUndefined();
});

it('does not shift date by timezone offset', () => {
const pipe = new PrDatePipe();

expect(pipe.transform('2020-06-10', cdtTimezone, 'date')).toBe(
'2020-06-10',
);
});

it('returns undefined for time part even with a timezone', () => {
const pipe = new PrDatePipe();

expect(pipe.transform('2020-06-10', cdtTimezone, 'time')).toBeUndefined();
});
});

// it('transforms a DST date in Pacific time', () => {
// const pipe = new PrDatePipe();
// const displayDT = formatDateISOString('2017-05-13T16:36:29.000000');
Expand Down
5 changes: 5 additions & 0 deletions src/app/shared/pipes/pr-date.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export class PrDatePipe implements PipeTransform {
return;
}

if (typeof dtString === 'string' && !dtString.includes('T')) {
if (part === 'time') return;
return moment.utc(dtString).format(MOMENT_DATE_FORMAT.date);
}

const dt = moment.utc(dtString);

let outputDt: moment.Moment;
Expand Down
38 changes: 38 additions & 0 deletions src/app/shared/services/edtf-service/edtf.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1283,4 +1283,42 @@ describe('EdtfService', () => {
expect(result).toBe(edtfString);
});
});

describe('getEdtfIntervalStartDate', () => {
it('should return the start date of an interval', () => {
expect(service.getEdtfIntervalStartDate('1985-05-20/1990-06-15')).toBe(
'1985-05-20',
);
});

it('should preserve the wall-clock time and offset of the start', () => {
expect(
service.getEdtfIntervalStartDate(
'2020-06-10T06:58:00-05:00/2026-06-15T00:00:00Z',
),
).toBe('2020-06-10T06:58:00-05:00');
});

it('should return a non-interval value unchanged', () => {
expect(service.getEdtfIntervalStartDate('1985-05-20')).toBe('1985-05-20');
});

it('should return an empty string for an empty input', () => {
expect(service.getEdtfIntervalStartDate('')).toBe('');
});

it('should return an empty string for an undefined input', () => {
expect(service.getEdtfIntervalStartDate(undefined)).toBe('');
});

it('should return an empty string for an open-ended start', () => {
expect(service.getEdtfIntervalStartDate('../1990-06-15')).toBe('');
});

it('should return the start when the end is open-ended', () => {
expect(service.getEdtfIntervalStartDate('1985-05-20/..')).toBe(
'1985-05-20',
);
});
});
});
13 changes: 13 additions & 0 deletions src/app/shared/services/edtf-service/edtf.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ export class EdtfService {
}
}

getEdtfIntervalStartDate(edtfString: string | undefined): string {
if (!edtfString) {
return '';
}

if (!edtfString.includes('/')) {
return edtfString;
}

const [startPart] = edtfString.split('/');
return startPart === '..' ? '' : (startPart ?? '');
}

private parseInterval(edtfString: string): DateTimeModel | null {
const [startPart, endPart] = edtfString.split('/');

Expand Down