Skip to content
Snippets Groups Projects
Commit e7c2b2f9 authored by jvanboxtel@wisc.edu's avatar jvanboxtel@wisc.edu
Browse files

Update academic year pipe to work new data

parent e255ce77
No related branches found
No related tags found
No related merge requests found
Pipeline #30940 passed
......@@ -26,7 +26,7 @@
<mat-expansion-panel class="year-container"[expanded]="true">
<mat-expansion-panel-header>
<mat-panel-title>
{{ term[0].year }}
{{ term[0].year | academicYearState }}
</mat-panel-title>
</mat-expansion-panel-header>
<div fxLayout="row" fxLayout.lt-md="column" fxLayoutGap="20px" fxLayoutAlign="start stretch" class="term-container-wrapper">
......
import { ActivatedRoute } from '@angular/router';
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
......@@ -5,29 +6,25 @@ import { Pipe, PipeTransform } from '@angular/core';
})
export class AcademicYearStatePipe implements PipeTransform {
terms = [];
constructor(private route: ActivatedRoute) {
this.terms = route.snapshot.data.requiredData.terms.map(t => t.termCode);
}
transform(yearCode: string, args?: any): any {
// Get the century digit
const century = parseInt(yearCode.substring(0, 1), 0) + 19;
// Get the year
const academicYear = parseInt(yearCode.substring(1), 0);
const endYear = (century * 100) + academicYear;
const startYear = endYear - 1;
const yearString = `${startYear} - ${endYear}`;
const currentYear = new Date().getFullYear();
if (currentYear === (startYear)) {
return `Current: ${yearString}`;
} else if (startYear > currentYear) {
return `Future: ${yearString}`;
} else if (startYear < currentYear) {
return `Past: ${yearString}`;
transform(year: string): string {
const termCode = this.terms[0];
let century = 2000;
if (termCode.substr(0, 1) === '0') {
century = 1900;
}
const YYYY = century + Number(year);
if (year < termCode.substr(1, 2)) {
return 'Past: ' + (YYYY - 1) + '-' + YYYY;
} else if (year > termCode.substr(1, 2)) {
return 'Future: ' + (YYYY - 1) + '-' + YYYY;
} else {
return 'Current: ' + (YYYY - 1) + '-' + YYYY;
}
return yearString;
}
}
......@@ -39,11 +39,14 @@ const modules = [
MatInputModule,
MatTooltipModule
];
const pipes = [
GetTermDescriptionPipe, AcademicYearStatePipe, AcademicYearRangePipe
];
@NgModule({
imports: [ modules ],
exports: [ modules, GetTermDescriptionPipe, AcademicYearStatePipe, CourseDetailsComponent, AcademicYearRangePipe ],
declarations: [ GetTermDescriptionPipe, AcademicYearStatePipe, CourseDetailsComponent, AcademicYearRangePipe ]
exports: [ modules, pipes, CourseDetailsComponent ],
declarations: [ pipes, CourseDetailsComponent ]
})
export class SharedModule { }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment