OpenSlides/client/src/app/shared/date-adapter.ts
Maximilian Krambach 5c1092b537 implement settings
Whats still missing, but has not a high priority:
- DateTimePicker. Entering dates through the popup works (but only with
a hack in the config-field.component update() method). Displaying values
from the server does not work. Also the localisation is missing. See
attempts to fix it in the sheared module.
- Errors, if the server cannot be reached. Should be solved in another
PR fixing the datasendservice and make generic error messages.
- Custom translations are missing
2018-10-09 13:06:44 +02:00

30 lines
962 B
TypeScript

import { Injectable } from '@angular/core';
import { NativeDateAdapter } from '@angular/material';
/**
* A custom DateAdapter for the datetimepicker in the config. This is still not fully working and needs to be done later.
* See comments in PR #3895.
*/
@Injectable()
export class OpenSlidesDateAdapter extends NativeDateAdapter {
public format(date: Date, displayFormat: Object): string {
if (displayFormat === 'input') {
return this.toFullIso8601(date);
} else {
return date.toDateString();
}
}
private to2digit(n: number): string {
return ('00' + n).slice(-2);
}
public toFullIso8601(date: Date): string {
return (
[date.getUTCFullYear(), this.to2digit(date.getUTCMonth() + 1), this.to2digit(date.getUTCDate())].join('-') +
'T' +
[this.to2digit(date.getUTCHours()), this.to2digit(date.getUTCMinutes())].join(':')
);
}
}