Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

Commit

Permalink
Safari Time Formatting (#298)
Browse files Browse the repository at this point in the history
* fixed up the send date fallbacks again

* gave localizations string a better name

* added support for dropdown time selection in safari

* changed console error to toast error

* fixed formatting for previous value safari times
  • Loading branch information
Addison Beck committed Mar 8, 2021
1 parent 0620464 commit 125de0d
Showing 1 changed file with 84 additions and 77 deletions.
161 changes: 84 additions & 77 deletions src/angular/components/send/add-edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ export class AddEditComponent implements OnInit {

safariDeletionTime: string;
safariExpirationTime: string;
safariDeletionTimeOptions: TimeOption[];
safariExpirationTimeOptions: TimeOption[];

private webVaultUrl: string;

Expand Down Expand Up @@ -116,83 +118,6 @@ export class AddEditComponent implements OnInit {
return !(this.platformUtilsService.isFirefox() || this.platformUtilsService.isSafari());
}

safariTimeOptions(field: DateField): TimeOption[] {
// init individual arrays for major sort groups
const noon: TimeOption[] = [];
const midnight: TimeOption[] = [];
const ams: TimeOption[] = [];
const pms: TimeOption[] = [];

// determine minute skip (5 min, 10 min, 15 min, etc.)
const minuteIncrementer = 15;

// loop through each hour on a 12 hour system
for (let h = 1; h <= 12; h++) {
// loop through each minute in the hour using the skip to incriment
for (let m = 0; m < 60; m += minuteIncrementer) {
// init the final strings that will be added to the lists
let hour = h.toString();
let minutes = m.toString();

// add prepending 0s to single digit hours/minutes
if (h < 10) {
hour = '0' + hour;
}
if (m < 10) {
minutes = '0' + minutes;
}

// build time strings and push to relevant sort groups
if (h === 12) {
const midnightOption: TimeOption = {
standard: `${hour}:${minutes} AM`,
military: `00:${minutes}`,
};
midnight.push(midnightOption);

const noonOption: TimeOption = {
standard: `${hour}:${minutes} PM`,
military: `${hour}:${minutes}`,
};
noon.push(noonOption);
} else {
const amOption: TimeOption = {
standard: `${hour}:${minutes} AM`,
military: `${hour}:${minutes}`,
};
ams.push(amOption);

const pmOption: TimeOption = {
standard: `${hour}:${minutes} PM`,
military: `${h + 12}:${minutes}`,
};
pms.push(pmOption);
}
}
}

// bring all the arrays together in the right order
const validTimes = [...midnight, ...ams, ...noon, ...pms];

// determine if an unsupported value already exists on the send & add that to the top of the option list
// example: if the Send was created with a different client
if (field === DateField.ExpriationDate && this.expirationDateTimeFallback != null) {
const previousValue: TimeOption = {
standard: this.datePipe.transform(this.expirationDateTimeFallback, 'HH:mm a'),
military: this.datePipe.transform(this.expirationDateTimeFallback, 'HH:mm'),
};
return [previousValue, {standard: null, military: null}, ...validTimes];
} else if (field === DateField.DeletionDate && this.deletionDateTimeFallback != null) {
const previousValue: TimeOption = {
standard: this.datePipe.transform(this.deletionDateTimeFallback, 'HH:mm a'),
military: this.datePipe.transform(this.deletionDateTimeFallback, 'HH:mm'),
};
return [previousValue, ...validTimes];
} else {
return [{standard: null, military: null}, ...validTimes];
}
}

async ngOnInit() {
await this.load();
}
Expand Down Expand Up @@ -276,6 +201,11 @@ export class AddEditComponent implements OnInit {
this.deletionDate = this.dateToString(this.send.deletionDate);
this.expirationDate = this.dateToString(this.send.expirationDate);
}

if (this.isSafari) {
this.safariDeletionTimeOptions = this.safariTimeOptions(DateField.DeletionDate);
this.safariExpirationTimeOptions = this.safariTimeOptions(DateField.ExpriationDate);
}
}

async submit(): Promise<boolean> {
Expand Down Expand Up @@ -482,4 +412,81 @@ export class AddEditComponent implements OnInit {
protected nullOrWhiteSpaceCount(strarray: string[]): number {
return strarray.filter(str => str == null || str.trim() === '').length;
}

protected safariTimeOptions(field: DateField): TimeOption[] {
// init individual arrays for major sort groups
const noon: TimeOption[] = [];
const midnight: TimeOption[] = [];
const ams: TimeOption[] = [];
const pms: TimeOption[] = [];

// determine minute skip (5 min, 10 min, 15 min, etc.)
const minuteIncrementer = 15;

// loop through each hour on a 12 hour system
for (let h = 1; h <= 12; h++) {
// loop through each minute in the hour using the skip to incriment
for (let m = 0; m < 60; m += minuteIncrementer) {
// init the final strings that will be added to the lists
let hour = h.toString();
let minutes = m.toString();

// add prepending 0s to single digit hours/minutes
if (h < 10) {
hour = '0' + hour;
}
if (m < 10) {
minutes = '0' + minutes;
}

// build time strings and push to relevant sort groups
if (h === 12) {
const midnightOption: TimeOption = {
standard: `${hour}:${minutes} AM`,
military: `00:${minutes}`,
};
midnight.push(midnightOption);

const noonOption: TimeOption = {
standard: `${hour}:${minutes} PM`,
military: `${hour}:${minutes}`,
};
noon.push(noonOption);
} else {
const amOption: TimeOption = {
standard: `${hour}:${minutes} AM`,
military: `${hour}:${minutes}`,
};
ams.push(amOption);

const pmOption: TimeOption = {
standard: `${hour}:${minutes} PM`,
military: `${h + 12}:${minutes}`,
};
pms.push(pmOption);
}
}
}

// bring all the arrays together in the right order
const validTimes = [...midnight, ...ams, ...noon, ...pms];

// determine if an unsupported value already exists on the send & add that to the top of the option list
// example: if the Send was created with a different client
if (field === DateField.ExpriationDate && this.expirationDateTimeFallback != null) {
const previousValue: TimeOption = {
standard: this.datePipe.transform(this.expirationDateTimeFallback, 'hh:mm a'),
military: this.datePipe.transform(this.expirationDateTimeFallback, 'HH:mm'),
};
return [previousValue, {standard: null, military: null}, ...validTimes];
} else if (field === DateField.DeletionDate && this.deletionDateTimeFallback != null) {
const previousValue: TimeOption = {
standard: this.datePipe.transform(this.deletionDateTimeFallback, 'hh:mm a'),
military: this.datePipe.transform(this.deletionDateTimeFallback, 'HH:mm'),
};
return [previousValue, ...validTimes];
} else {
return [{standard: null, military: null}, ...validTimes];
}
}
}

0 comments on commit 125de0d

Please sign in to comment.