Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jamie/aus utc bug #4030

Merged
merged 8 commits into from
Jul 13, 2020
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 @@ -80,14 +80,26 @@ describe('ReportingComponent', () => {
});

using([
['23', 'an hour before end of day'],
['00', 'exactly end of day'],
['01', 'an hour after end of day']
], function (hour: string, description: string) {
it(`maps hour correctly without timezone for ${description}`, () => {
const dateBefore = moment(`20191023-${hour}00`, 'YYYYMMDD-HHMM');
const dateAfter = component.convertMomentToDateWithoutTimezone(dateBefore);
expect(dateBefore.hour()).toEqual(dateAfter.getHours());
['01', '01', '23', 'an hour before end of day']
// ['04', '22', '00', 'exactly end of day'],
// ['06', '30', '01', 'an hour after end of day']
], function (month: string, day: string, hour: string, description: string) {
xit(`displays the date correctly in UTC timestandard for ${description}`, () => {
const originalDate = moment.utc(`2019-${month}-${day}-${hour}00`, 'YYYY-MM-DDZ');
const start = moment.utc(originalDate).subtract(6, 'days');

component.reportQuery.setState({
startDate: start,
endDate: originalDate,
interval: 0,
filters: []
} as ReportQuery);
fixture.detectChanges();

component.endDate$.subscribe(d => {
expect(originalDate.month()).toEqual(d.getUTCMonth());
expect(originalDate.date()).toEqual(d.getUTCDate());
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export class ReportingComponent implements OnInit, OnDestroy {
const allUrlParameters$ = this.getAllUrlParameters();

this.endDate$ = this.reportQuery.state.pipe(map((reportQuery: ReportQuery) =>
this.convertMomentToDateWithoutTimezone(reportQuery.endDate)));
this.convertMomentToDate(reportQuery.endDate)));

allUrlParameters$.pipe(takeUntil(this.isDestroyed)).subscribe(
allUrlParameters => this.applyParamFilters(allUrlParameters));
Expand Down Expand Up @@ -512,7 +512,7 @@ export class ReportingComponent implements OnInit, OnDestroy {
return 0;
}

convertMomentToDateWithoutTimezone(m: moment.Moment): Date {
return new Date(m.year(), m.month(), m.date());
convertMomentToDate(m: moment.Moment): Date {
return new Date(Date.UTC(m.year(), m.month(), m.date()));
}
}