Skip to content

Commit

Permalink
Minor changes to the options of the date picker.
Browse files Browse the repository at this point in the history
  • Loading branch information
KekeH committed Dec 2, 2015
1 parent 6c9a43d commit 22a26de
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/app/css/mydatepicker.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}

.mydatepicker .selector {
margin-top: 3px;
margin-top: 2px;
margin-left: -1px;
position: absolute;
max-width: 262px;
Expand Down
21 changes: 15 additions & 6 deletions src/app/mydatepicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export class MyDatePicker {
constructor() {}

onInit() {
this.dayLabels = this.options.dayLabels !== undefined ? this.options.dayLabels : this.dayLabels;
this.monthLabels = this.options.monthLabels !== undefined ? this.options.monthLabels : this.monthLabels;
this.dateFormat = this.options.dateFormat !== undefined ? this.options.dateFormat : this.dateFormat;
this.firstDayOfWeek = this.options.firstDayOfWeek !== undefined ? this.options.firstDayOfWeek : this.firstDayOfWeek;
this.sunHighlight = this.options.sunHighlight !== undefined ? this.options.sunHighlight : this.sunHighlight;
Expand All @@ -57,16 +59,22 @@ export class MyDatePicker {

removeBtnClicked() {
this.selectionDayTxt = '';
this.selectedDate = {};
this.dateChanged.next({date: {}, formatted: this.selectionDayTxt});
this.selectedDate = {year:0, month:0, day:0};
this.dateChanged.next({date: {}, formatted: this.selectionDayTxt, epoc: 0});
}

openBtnClicked() {
this.showSelector = !this.showSelector;
if (this.showSelector) {
var y = this.today.getFullYear();
var m = this.today.getMonth() + 1;

var y = 0, m = 0;
if(this.selectedDate.year === 0 && this.selectedDate.month === 0 && this.selectedDate.day === 0) {
y = this.today.getFullYear();
m = this.today.getMonth() + 1;
}
else {
y = this.selectedDate.year;
m = this.selectedDate.month;
}
// Set current month
this.visibleMonth = {monthTxt: this.monthLabels[m], monthNbr: m, year: y};

Expand Down Expand Up @@ -131,7 +139,8 @@ export class MyDatePicker {
this.selectedDate = {day: cell.day, month: cell.month, year: cell.year};
this.selectionDayTxt = this.formatDate(cell);
this.showSelector = false;
this.dateChanged.next({date: this.selectedDate, formatted: this.selectionDayTxt});
var epoc = new Date(cell.year, cell.month - 1, cell.day, 0, 0, 0, 0).getTime()/1000.0;
this.dateChanged.next({date: this.selectedDate, formatted: this.selectionDayTxt, epoc: epoc});
}
else if (cell.cmo === this.NEXT_MONTH) {
// Next month of day
Expand Down
2 changes: 1 addition & 1 deletion src/app/sampleapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SampleDatePicker {
}

onDateChanged(event) {
console.log('onDateChanged(): ', event.date, ' - formatted: ', event.formatted);
console.log('onDateChanged(): ', event.date, ' - formatted: ', event.formatted, ' - epoc timestamp: ', event.epoc);
}
}
bootstrap(SampleDatePicker);

0 comments on commit 22a26de

Please sign in to comment.