Skip to content
This repository was archived by the owner on Mar 2, 2018. It is now read-only.

Commit 65b35ed

Browse files
committed
issue #135, able to pick up current time
1 parent c285db0 commit 65b35ed

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/ng2-datetime-picker.component.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ declare var moment: any;
2323
selector : 'ng2-datetime-picker',
2424
template : `
2525
<div class="ng2-datetime-picker">
26-
<div class="close-button" *ngIf="showCloseButton" (click)="close()">X</div>
26+
<div class="close-button" *ngIf="showCloseButton" (click)="close()"></div>
2727
2828
<!-- Month - Year -->
2929
<div class="month" *ngIf="!timeOnly">
@@ -82,6 +82,7 @@ declare var moment: any;
8282
8383
<!-- Time -->
8484
<div class="time" id="time" *ngIf="!dateOnly">
85+
<div class="select-current-time" (click)="selectCurrentTime()"></div>
8586
<label class="timeLabel">Time:</label>
8687
<span class="timeValue">
8788
{{("0"+hour).slice(-2)}} : {{("0"+minute).slice(-2)}}
@@ -128,7 +129,8 @@ declare var moment: any;
128129
animation: slideDown 0.1s ease-in-out;
129130
animation-fill-mode: both;
130131
}
131-
.ng2-datetime-picker .close-button {
132+
.ng2-datetime-picker .close-button:before {
133+
content: 'X';
132134
position: absolute;
133135
padding: 0 5px;
134136
cursor: pointer;
@@ -212,6 +214,18 @@ declare var moment: any;
212214
clear: left;
213215
height: 0;
214216
}
217+
.ng2-datetime-picker .time {
218+
position: relative;
219+
}
220+
.ng2-datetime-picker .select-current-time:before {
221+
content: 'current time';
222+
position: absolute;
223+
top: 1em;
224+
right: 5px;
225+
z-index: 1;
226+
cursor: pointer;
227+
color: #0000ff;
228+
}
215229
.ng2-datetime-picker .hourLabel,
216230
.ng2-datetime-picker .minutesLabel {
217231
display: inline-block;
@@ -329,6 +343,12 @@ export class Ng2DatetimePickerComponent {
329343
return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0, 0);
330344
}
331345

346+
public selectCurrentTime(){
347+
this.hour = (new Date()).getHours();
348+
this.minute = (new Date()).getMinutes();
349+
this.selectDateTime();
350+
}
351+
332352
/**
333353
* set the selected date and close it when closeOnSelect is true
334354
* @param date {Date}

0 commit comments

Comments
 (0)