Skip to content

Commit fc30ba5

Browse files
author
ijz953
committed
docs: refactor to use UTC YYYY-MM-DD format and moved date range function into a pipe
1 parent 387753c commit fc30ba5

File tree

9 files changed

+172
-96
lines changed

9 files changed

+172
-96
lines changed

projects/ngrx.io/content/marketing/events.json

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,111 +3,113 @@
33
"name": "NgColombia",
44
"url": "http://www.ngcolombia.com",
55
"location": "Medellín, Colombia",
6-
"startDate": "09-06-2018",
7-
"endDate": "09-07-2018"
6+
"startDate": "2018-09-06",
7+
"endDate": "2018-09-07"
88
},
99
{
1010
"name": "DevFestATL",
1111
"url": "http://devfestatl.com",
1212
"location": "Atlanta, Georgia",
13-
"endDate": "09-22-2018"
13+
"endDate": "2018-09-22"
1414
},
1515
{
1616
"name": "Framework Summit",
1717
"url": "http://frameworksummit.com",
1818
"location": "Park City, Utah",
19-
"endDate": "09-22-2018"
19+
"endDate": "2018-09-22"
2020
},
2121
{
2222
"name": "DevFestATL",
2323
"url": "http://devfestatl.com",
2424
"location": "Atlanta, Georgia",
25-
"startDate": "10-02-2018",
26-
"endDate": "10-03-2018"
25+
"startDate": "2018-10-02",
26+
"endDate": "2018-10-03"
2727
},
2828
{
2929
"name": "AngularMix",
3030
"url": "http://www.angularmix.com",
3131
"location": "Orlando, Florida",
32-
"startDate": "10-10-2018",
33-
"endDate": "10-12-2018"
32+
"startDate": "2018-10-10",
33+
"endDate": "2018-10-12"
3434
},
3535
{
3636
"name": "AngularConnect",
37-
"url": "http://www.angularconnect.com",
37+
"url": "https://www.angularconnect.com",
3838
"location": "Excel, London",
39-
"startDate": "11-06-2018",
40-
"endDate": "11-07-2018"
39+
"startDate": "2018-11-06",
40+
"endDate": "2018-11-07"
4141
},
4242
{
4343
"name": "ngAtlanta",
4444
"url": "http://ng-atl.org/",
4545
"location": "Atlanta, Georgia",
46-
"startDate": "01-09-2019",
47-
"endDate": "01-12-2019"
46+
"startDate": "2019-01-09",
47+
"endDate": "2019-01-12"
4848
},
4949
{
5050
"name": "ng-India",
5151
"url": "https://www.ng-ind.com",
5252
"location": "Gurgaon, India",
53-
"endDate": "02-23-2019"
53+
"endDate": "2019-02-23"
5454
},
5555
{
5656
"name": "Open Source 101",
5757
"url": "https://opensource101.com/",
5858
"location": "Columbia, South Carolina",
59-
"endDate": "04-18-2019"
59+
"endDate": "2019-04-18"
6060
},
6161
{
6262
"name": "NG-Conf",
6363
"url": "https://www.ng-conf.org",
6464
"location": "Salt Lake City, Utah",
65-
"startDate": "05-01-2019", "endDate": "05-03-2019"},
65+
"startDate": "2019-05-01",
66+
"endDate": "2019-05-03"
67+
},
6668
{
6769
"name": "ngVikings",
6870
"url": "https://ngvikings.org/",
6971
"location": "Copenhagen, Denmark",
70-
"startDate": "05-26-2019",
71-
"endDate": "05-28-2019"
72+
"startDate": "2019-05-26",
73+
"endDate": "2019-05-28"
7274
},
7375
{
7476
"name": "REFACTR.TECH",
7577
"url": "https://refactr.tech/",
7678
"location": "Atlanta, Georgia",
77-
"startDate": "06-05-2019",
78-
"endDate": "06-07-2019"
79+
"startDate": "2019-06-05",
80+
"endDate": "2019-06-07"
7981
},
8082
{
8183
"name": "AngularUP",
8284
"url": "https://angular-up.com/",
8385
"location": "Tel Aviv, Israel",
84-
"endDate": "06-12-2019"
86+
"endDate": "2019-06-12"
8587
},
8688
{
8789
"name": "NG-MY",
8890
"url": "https://ng-my.org/",
8991
"location": "Kuala Lumpur, Malaysia",
90-
"startDate": "07-06-2019",
91-
"endDate": "07-07-2019"
92+
"startDate": "2019-07-06",
93+
"endDate": "2019-07-07"
9294
},
9395
{
9496
"name": "ngDenver",
9597
"url": "http://angulardenver.com/",
9698
"location": "Denver, Colorado",
97-
"startDate": "08-01-2019",
98-
"endDate": "08-02-2019"
99+
"startDate": "2019-08-01",
100+
"endDate": "2019-08-02"
99101
},
100102
{
101103
"name": "AngularConnect",
102104
"url": "https://www.angularconnect.com/",
103105
"location": "London, United Kingdom",
104-
"startDate": "09-19-2019",
105-
"endDate": "09-20-2019"
106+
"startDate": "2019-09-19",
107+
"endDate": "2019-09-20"
106108
},
107109
{
108110
"name": "NG-Rome",
109111
"url": "https://ngrome.io/",
110112
"location": "Rome, Italy",
111-
"endDate": "10-07-2019"
113+
"endDate": "2019-10-07"
112114
}
113115
]
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { EventDateRangePipe } from './event-date-range.pipe';
2+
import { Event } from './event.model';
3+
4+
describe('Pipe: Event Date Range', () => {
5+
let pipe: EventDateRangePipe;
6+
7+
beforeEach(() => {
8+
pipe = new EventDateRangePipe();
9+
});
10+
11+
it('providing no startDate should format only the endDate in MM DD, YYYY', () => {
12+
const event: Event = {
13+
name: '',
14+
url: '',
15+
location: '',
16+
endDate: new Date('2019-01-01')
17+
};
18+
expect(pipe.transform(event)).toBe('January 1, 2019');
19+
});
20+
21+
it('providing the same startDate and endDate should format only one in MM DD, YYYY', () => {
22+
const event: Event = {
23+
name: '',
24+
url: '',
25+
location: '',
26+
startDate: new Date('2019-01-01'),
27+
endDate: new Date('2019-01-01')
28+
};
29+
expect(pipe.transform(event)).toBe('January 1, 2019');
30+
});
31+
32+
it('providing different days in the same month and year should format in MM DD - DD, YYYY format', () => {
33+
const event: Event = {
34+
name: '',
35+
url: '',
36+
location: '',
37+
startDate: new Date('2019-01-01'),
38+
endDate: new Date('2019-01-02')
39+
};
40+
expect(pipe.transform(event)).toBe('January 1 - 2, 2019');
41+
});
42+
43+
it('providing different days and months in the same year should format in MM DD - MM DD, YYYY format', () => {
44+
const event: Event = {
45+
name: '',
46+
url: '',
47+
location: '',
48+
startDate: new Date('2019-01-01'),
49+
endDate: new Date('2019-01-02')
50+
};
51+
expect(pipe.transform(event)).toBe('January 1 - 2, 2019');
52+
});
53+
54+
it('providing different days, months, and years should format in MM DD, YYYY - MM DD, YYYY format', () => {
55+
const event: Event = {
56+
name: '',
57+
url: '',
58+
location: '',
59+
startDate: new Date('2018-12-31'),
60+
endDate: new Date('2019-01-01')
61+
};
62+
expect(pipe.transform(event)).toBe('December 31, 2018 - January 1, 2019');
63+
});
64+
});
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { Pipe, PipeTransform } from '@angular/core';
2+
import { Event } from './event.model';
3+
4+
/**
5+
* Transforms the startDate and endDate for a given event into a dange range string.
6+
* undefined until '01-01-2019' -> 'January 1, 2019'
7+
* '01-01-2019' until '01-01-2019' -> 'January 1, 2019'
8+
* '01-01-2019' until '01-02-2019' -> 'January 1 - 2, 2019'
9+
* '01-28-2019' until '02-01-2019' -> 'January 28 - February 1, 2019'
10+
* '12-31-2018' until '01-01-2019' -> 'December 31, 2018 - January 1, 2019'
11+
*/
12+
@Pipe({name: 'eventDateRange'})
13+
export class EventDateRangePipe implements PipeTransform {
14+
transform(event: Event): string {
15+
const startDate = event.startDate;
16+
const endDate = event.endDate;
17+
if (!startDate || startDate.getTime() === endDate.getTime()) {
18+
return getDateString(endDate);
19+
} else {
20+
if (getMonth(startDate) === getMonth(endDate) && getYear(startDate) === getYear(endDate)) {
21+
return getMonth(startDate)
22+
+ ' ' + getDay(startDate) + ' - ' + getDay(endDate)
23+
+ ', ' + getYear(startDate);
24+
} else if (getYear(startDate) === getYear(endDate)) {
25+
return getMonth(startDate)
26+
+ ' ' + getDay(startDate)
27+
+ ' - ' + getMonth(endDate)
28+
+ ' ' + getDay(endDate)
29+
+ ', ' + getYear(startDate);
30+
} else {
31+
return getDateString(startDate)
32+
+ ' - ' + getDateString(endDate);
33+
}
34+
}
35+
}
36+
}
37+
38+
const getDay = (date: Date) => date.getUTCDate();
39+
const getMonth = (date: Date) => months[date.getUTCMonth()];
40+
const getYear = (date: Date) => date.getUTCFullYear();
41+
const getDateString = (date: Date) => getMonth(date) + ' ' + getDay(date) + ', ' + getYear(date);
42+
const months = [
43+
'January',
44+
'February',
45+
'March',
46+
'April',
47+
'May',
48+
'June',
49+
'July',
50+
'August',
51+
'September',
52+
'October',
53+
'November',
54+
'December'
55+
];

projects/ngrx.io/src/app/custom-elements/events/event-list.component.spec.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import { EventListComponent } from './event-list.component';
33
import { of } from 'rxjs';
44
import { EventService } from './event.service';
55
import { Event } from './event.model';
6+
import { EventDateRangePipe } from './event-date-range.pipe';
67

78
const mockUpcomingEvents: Event[] = [
89
{
910
name: 'NG-Rome',
1011
url: 'https://ngrome.io/',
1112
location: 'Rome, Italy',
12-
endDate: new Date('10-07-2019'),
13-
dateRangeString: 'October 7, 2019'
13+
endDate: new Date('2019-10-07')
1414
}
1515
];
1616

@@ -19,8 +19,7 @@ const mockPastEvents: Event[] = [
1919
name: 'DevFestATL',
2020
url: 'http://devfestatl.com',
2121
location: 'Atlanta, Georgia',
22-
endDate: new Date('09-22-2018'),
23-
dateRangeString: 'September 22, 2018'
22+
endDate: new Date('2018-09-22')
2423
}
2524
];
2625

@@ -36,7 +35,7 @@ describe('Event List Component', () => {
3635

3736
beforeEach(() => {
3837
TestBed.configureTestingModule({
39-
declarations: [ EventListComponent ],
38+
declarations: [ EventListComponent, EventDateRangePipe ],
4039
providers: [{ provide: EventService, useClass: TestEventService }]
4140
});
4241

projects/ngrx.io/src/app/custom-elements/events/event-list.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { Observable } from 'rxjs';
1919
<tr *ngFor="let upcomingEvent of upcomingEvents$ | async">
2020
<th><a [href]="upcomingEvent.url" [title]="upcomingEvent.name">{{upcomingEvent.name}}</a></th>
2121
<td>{{upcomingEvent.location}}</td>
22-
<td>{{upcomingEvent.dateRangeString}}</td>
22+
<td>{{upcomingEvent | eventDateRange}}</td>
2323
</tr>
2424
</tbody>
2525
</table>
@@ -36,7 +36,7 @@ import { Observable } from 'rxjs';
3636
<tr *ngFor="let pastEvent of pastEvents$ | async">
3737
<th><a [href]="pastEvent.url" [title]="pastEvent.name">{{pastEvent.name}}</a></th>
3838
<td>{{pastEvent.location}}</td>
39-
<td>{{pastEvent.dateRangeString}}</td>
39+
<td>{{pastEvent | eventDateRange}}</td>
4040
</tr>
4141
</tbody>
4242
</table>

projects/ngrx.io/src/app/custom-elements/events/event-list.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { CommonModule } from '@angular/common';
33
import { WithCustomElementComponent } from '../element-registry';
44
import { EventListComponent } from './event-list.component';
55
import { EventService } from './event.service';
6+
import { EventDateRangePipe } from './event-date-range.pipe';
67

78
@NgModule({
89
imports: [ CommonModule ],
9-
declarations: [ EventListComponent ],
10+
declarations: [ EventListComponent, EventDateRangePipe ],
1011
entryComponents: [ EventListComponent ],
1112
providers: [ EventService ]
1213
})

projects/ngrx.io/src/app/custom-elements/events/event.model.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ export interface Event {
1212
location: string;
1313
startDate?: Date;
1414
endDate: Date;
15-
dateRangeString: string;
1615
}

0 commit comments

Comments
 (0)