Skip to content

Commit

Permalink
refactor(timepicker): transform input props to config props only
Browse files Browse the repository at this point in the history
  • Loading branch information
juicyarts committed Nov 14, 2021
1 parent 4cce2a7 commit d7d5d48
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 32 deletions.
6 changes: 0 additions & 6 deletions apps/ngx-bootstrap-docs/src/ng-api-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4315,12 +4315,6 @@ export const ngdoc: any = {
"defaultValue": "true",
"type": "boolean",
"description": "<p>if true spinner arrows above and below the inputs will be shown</p>\n"
},
{
"name": "useUtc",
"defaultValue": "false",
"type": "boolean",
"description": "<p>if true displays utc time instead of client time</p>\n"
}
],
"outputs": [
Expand Down
8 changes: 1 addition & 7 deletions libs/doc-pages/timepicker/src/lib/demos/use-utc/use-utc.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
<timepicker [(ngModel)]="myTime" [useUtc]="useUtc"></timepicker>

<div class="row my-3">
<div class="col-xs-6 col-6 col-md-4">
<button type="button" class="btn btn-info" (click)="useUtc = !useUtc">useUtc: {{useUtc}}</button>
</div>
</div>
<timepicker [(ngModel)]="myTime"></timepicker>

<pre class="alert alert-info">Time is: {{myTime}}</pre>
11 changes: 9 additions & 2 deletions libs/doc-pages/timepicker/src/lib/demos/use-utc/use-utc.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { Component } from '@angular/core';
import { TimepickerConfig } from 'ngx-bootstrap/timepicker';

export function getTimepickerConfig(): TimepickerConfig {
return Object.assign(new TimepickerConfig(), {
useUtc: true
});
}

@Component({
// eslint-disable-next-line @angular-eslint/component-selector
selector: 'demo-timepicker-use-utc',
templateUrl: './use-utc.html'
templateUrl: './use-utc.html',
providers: [{ provide: TimepickerConfig, useFactory: getTimepickerConfig }]
})
export class DemoTimepickerUseUtcComponent {
myTime: Date = new Date();
useUtc = false;
}
4 changes: 1 addition & 3 deletions src/timepicker/reducer/timepicker.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ export function timepickerReducer(state = initialState, action: Action) {
controls: _newControlsState
};

if (state.config.showMeridian !== _newState.config.showMeridian ||
state.config.useUtc !== _newState.config.useUtc
) {
if (state.config.showMeridian !== _newState.config.showMeridian) {
if (state.value) {
_newState.value = new Date(state.value);
}
Expand Down
3 changes: 1 addition & 2 deletions src/timepicker/testing/timepicker-controls.util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ describe('Util: Timepicker-controls', () => {
showSpinners: true,
showMeridian: true,
showSeconds: false,
meridians: ['AM', 'PM'],
useUtc: false
meridians: ['AM', 'PM']
};

controls = {
Expand Down
2 changes: 1 addition & 1 deletion src/timepicker/testing/timepicker.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@ describe('Component: TimepickerComponent', () => {

it('should show utc values instead of client values', () => {
const time = testTime(12, 0, 0);
component.useUtc = true;
component.config.useUtc = true;
component.writeValue(time);
fixture.detectChanges();
expect(inputHours.value).toBe(padNumber(time.getUTCHours()));
Expand Down
3 changes: 1 addition & 2 deletions src/timepicker/testing/timepicker.utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ const controls: TimepickerComponentState = {
showSpinners: false,
showMeridian: true,
showSeconds: true,
meridians: ['AM', 'PM'],
useUtc: false
meridians: ['AM', 'PM']
};

function testTime(hours?: number, minutes?: number, seconds?: number): Date {
Expand Down
6 changes: 2 additions & 4 deletions src/timepicker/timepicker-controls.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ export function getControlsValue(
showSeconds,
meridians,
min,
max,
useUtc
max
} = state;

return {
Expand All @@ -112,8 +111,7 @@ export function getControlsValue(
showSeconds,
meridians,
min,
max,
useUtc
max
};
}

Expand Down
6 changes: 2 additions & 4 deletions src/timepicker/timepicker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ export class TimepickerComponent
@Output() isValid = new EventEmitter<boolean>();
/** emits value of meridian*/
@Output() meridianChange = new EventEmitter<string>();
/** if true displays utc time instead of client time */
@Input() useUtc = false;
// ui variables
hours = '';
minutes = '';
Expand Down Expand Up @@ -411,8 +409,8 @@ export class TimepickerComponent
}

const _hoursPerDayHalf = 12;
let _hours = getHours(_value, this.useUtc);
const _minutes = getMinutes(_value, this.useUtc);
let _hours = getHours(_value, this.config.useUtc);
const _minutes = getMinutes(_value, this.config.useUtc);

if (this.showMeridian) {
this.meridian = this.meridians[_hours >= _hoursPerDayHalf ? 1 : 0];
Expand Down
1 change: 0 additions & 1 deletion src/timepicker/timepicker.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export interface TimepickerComponentState {
showSeconds: boolean;

meridians: string[];
useUtc: boolean;
}

export type TimeChangeSource = 'wheel' | 'key' | '';
Expand Down

0 comments on commit d7d5d48

Please sign in to comment.