bootstrap-datepicker-rails 0.6.16 → 0.6.17

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -73,6 +73,10 @@ $(document).on("focus", "[data-behaviour~='datepicker']", function(e){
73
73
 
74
74
  ```
75
75
 
76
+ Here is a live example:
77
+
78
+ http://jsfiddle.net/2Gg5k/43/
79
+
76
80
  There are a lot of options you can pass to datepicker(). They are documented at [https://github.com/eternicode/bootstrap-datepicker](https://github.com/eternicode/bootstrap-datepicker)
77
81
 
78
82
  ## Questions? Bugs?
@@ -1,5 +1,5 @@
1
1
  module BootstrapDatepickerRails
2
2
  module Rails
3
- VERSION = "0.6.16"
3
+ VERSION = "0.6.17"
4
4
  end
5
5
  end
@@ -20,6 +20,10 @@
20
20
 
21
21
  !function( $ ) {
22
22
 
23
+ function UTCDate(){
24
+ return new Date(Date.UTC.apply(Date, arguments));
25
+ }
26
+
23
27
  // Picker object
24
28
 
25
29
  var Datepicker = function(element, options){
@@ -248,35 +252,34 @@
248
252
 
249
253
  fill: function() {
250
254
  var d = new Date(this.viewDate),
251
- year = d.getFullYear(),
252
- month = d.getMonth(),
253
- startYear = this.startDate !== -Infinity ? this.startDate.getFullYear() : -Infinity,
254
- startMonth = this.startDate !== -Infinity ? this.startDate.getMonth() : -Infinity,
255
- endYear = this.endDate !== Infinity ? this.endDate.getFullYear() : Infinity,
256
- endMonth = this.endDate !== Infinity ? this.endDate.getMonth() : Infinity,
255
+ year = d.getUTCFullYear(),
256
+ month = d.getUTCMonth(),
257
+ startYear = this.startDate !== -Infinity ? this.startDate.getUTCFullYear() : -Infinity,
258
+ startMonth = this.startDate !== -Infinity ? this.startDate.getUTCMonth() : -Infinity,
259
+ endYear = this.endDate !== Infinity ? this.endDate.getUTCFullYear() : Infinity,
260
+ endMonth = this.endDate !== Infinity ? this.endDate.getUTCMonth() : Infinity,
257
261
  currentDate = this.date.valueOf();
258
262
  this.picker.find('.datepicker-days th:eq(1)')
259
263
  .text(dates[this.language].months[month]+' '+year);
260
264
  this.updateNavArrows();
261
265
  this.fillMonths();
262
- var prevMonth = new Date(year, month-1, 28,0,0,0,0),
263
- day = DPGlobal.getDaysInMonth(prevMonth.getFullYear(), prevMonth.getMonth()),
264
- prevDate, dstDay = 0, date;
265
- prevMonth.setDate(day);
266
- prevMonth.setDate(day - (prevMonth.getDay() - this.weekStart + 7)%7);
266
+ var prevMonth = UTCDate(year, month-1, 28,0,0,0,0),
267
+ day = DPGlobal.getDaysInMonth(prevMonth.getUTCFullYear(), prevMonth.getUTCMonth());
268
+ prevMonth.setUTCDate(day);
269
+ prevMonth.setUTCDate(day - (prevMonth.getUTCDay() - this.weekStart + 7)%7);
267
270
  var nextMonth = new Date(prevMonth);
268
- nextMonth.setDate(nextMonth.getDate() + 42);
271
+ nextMonth.setUTCDate(nextMonth.getUTCDate() + 42);
269
272
  nextMonth = nextMonth.valueOf();
270
273
  var html = [];
271
274
  var clsName;
272
275
  while(prevMonth.valueOf() < nextMonth) {
273
- if (prevMonth.getDay() == this.weekStart) {
276
+ if (prevMonth.getUTCDay() == this.weekStart) {
274
277
  html.push('<tr>');
275
278
  }
276
279
  clsName = '';
277
- if (prevMonth.getFullYear() < year || (prevMonth.getFullYear() == year && prevMonth.getMonth() < month)) {
280
+ if (prevMonth.getUTCFullYear() < year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() < month)) {
278
281
  clsName += ' old';
279
- } else if (prevMonth.getFullYear() > year || (prevMonth.getFullYear() == year && prevMonth.getMonth() > month)) {
282
+ } else if (prevMonth.getUTCFullYear() > year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() > month)) {
280
283
  clsName += ' new';
281
284
  }
282
285
  if (prevMonth.valueOf() == currentDate) {
@@ -285,45 +288,14 @@
285
288
  if (prevMonth.valueOf() < this.startDate || prevMonth.valueOf() > this.endDate) {
286
289
  clsName += ' disabled';
287
290
  }
288
- date = prevMonth.getDate();
289
- if (dstDay == -1) date++;
290
- html.push('<td class="day'+clsName+'">'+date+ '</td>');
291
- if (prevMonth.getDay() == this.weekEnd) {
291
+ html.push('<td class="day'+clsName+'">'+prevMonth.getUTCDate() + '</td>');
292
+ if (prevMonth.getUTCDay() == this.weekEnd) {
292
293
  html.push('</tr>');
293
294
  }
294
- prevDate = prevMonth.getDate();
295
- prevMonth.setDate(prevMonth.getDate()+1);
296
- if (prevMonth.getHours() != 0) {
297
- // Fix for DST bug: if we are no longer at start of day, a DST jump probably happened
298
- // We either fell back (eg, Jan 1 00:00 -> Jan 1 23:00)
299
- // or jumped forward (eg, Jan 1 00:00 -> Jan 2 01:00)
300
- // Unfortunately, I can think of no way to test this in the unit tests, as it depends
301
- // on the TZ of the client system.
302
- if (!dstDay) {
303
- // We are not currently handling a dst day (next round will deal with it)
304
- if (prevMonth.getDate() == prevDate)
305
- // We must compensate for fall-back
306
- dstDay = -1;
307
- else
308
- // We must compensate for a jump-ahead
309
- dstDay = +1;
310
- }
311
- else {
312
- // The last round was our dst day (hours are still non-zero)
313
- if (dstDay == -1)
314
- // For a fall-back, fast-forward to next midnight
315
- prevMonth.setHours(24);
316
- else
317
- // For a jump-ahead, just reset to 0
318
- prevMonth.setHours(0);
319
- // Reset minutes, as some TZs may be off by portions of an hour
320
- prevMonth.setMinutes(0);
321
- dstDay = 0;
322
- }
323
- }
295
+ prevMonth.setUTCDate(prevMonth.getUTCDate()+1);
324
296
  }
325
297
  this.picker.find('.datepicker-days tbody').empty().append(html.join(''));
326
- var currentYear = this.date.getFullYear();
298
+ var currentYear = this.date.getUTCFullYear();
327
299
 
328
300
  var months = this.picker.find('.datepicker-months')
329
301
  .find('th:eq(1)')
@@ -331,7 +303,7 @@
331
303
  .end()
332
304
  .find('span').removeClass('active');
333
305
  if (currentYear == year) {
334
- months.eq(this.date.getMonth()).addClass('active');
306
+ months.eq(this.date.getUTCMonth()).addClass('active');
335
307
  }
336
308
  if (year < startYear || year > endYear) {
337
309
  months.addClass('disabled');
@@ -360,16 +332,16 @@
360
332
 
361
333
  updateNavArrows: function() {
362
334
  var d = new Date(this.viewDate),
363
- year = d.getFullYear(),
364
- month = d.getMonth();
335
+ year = d.getUTCFullYear(),
336
+ month = d.getUTCMonth();
365
337
  switch (this.viewMode) {
366
338
  case 0:
367
- if (this.startDate !== -Infinity && year <= this.startDate.getFullYear() && month <= this.startDate.getMonth()) {
339
+ if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth()) {
368
340
  this.picker.find('.prev').css({visibility: 'hidden'});
369
341
  } else {
370
342
  this.picker.find('.prev').css({visibility: 'visible'});
371
343
  }
372
- if (this.endDate !== Infinity && year >= this.endDate.getFullYear() && month >= this.endDate.getMonth()) {
344
+ if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth()) {
373
345
  this.picker.find('.next').css({visibility: 'hidden'});
374
346
  } else {
375
347
  this.picker.find('.next').css({visibility: 'visible'});
@@ -377,12 +349,12 @@
377
349
  break;
378
350
  case 1:
379
351
  case 2:
380
- if (this.startDate !== -Infinity && year <= this.startDate.getFullYear()) {
352
+ if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear()) {
381
353
  this.picker.find('.prev').css({visibility: 'hidden'});
382
354
  } else {
383
355
  this.picker.find('.prev').css({visibility: 'visible'});
384
356
  }
385
- if (this.endDate !== Infinity && year >= this.endDate.getFullYear()) {
357
+ if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear()) {
386
358
  this.picker.find('.next').css({visibility: 'hidden'});
387
359
  } else {
388
360
  this.picker.find('.next').css({visibility: 'visible'});
@@ -420,17 +392,17 @@
420
392
  break;
421
393
  case 'span':
422
394
  if (!target.is('.disabled')) {
423
- this.viewDate.setDate(1);
395
+ this.viewDate.setUTCDate(1);
424
396
  if (target.is('.month')) {
425
397
  var month = target.parent().find('span').index(target);
426
- this.viewDate.setMonth(month);
398
+ this.viewDate.setUTCMonth(month);
427
399
  this.element.trigger({
428
400
  type: 'changeMonth',
429
401
  date: this.viewDate
430
402
  });
431
403
  } else {
432
404
  var year = parseInt(target.text(), 10)||0;
433
- this.viewDate.setFullYear(year);
405
+ this.viewDate.setUTCFullYear(year);
434
406
  this.element.trigger({
435
407
  type: 'changeYear',
436
408
  date: this.viewDate
@@ -443,8 +415,8 @@
443
415
  case 'td':
444
416
  if (target.is('.day') && !target.is('.disabled')){
445
417
  var day = parseInt(target.text(), 10)||1;
446
- var year = this.viewDate.getFullYear(),
447
- month = this.viewDate.getMonth();
418
+ var year = this.viewDate.getUTCFullYear(),
419
+ month = this.viewDate.getUTCMonth();
448
420
  if (target.is('.old')) {
449
421
  if (month == 0) {
450
422
  month = 11;
@@ -460,8 +432,8 @@
460
432
  month += 1;
461
433
  }
462
434
  }
463
- this.date = new Date(year, month, day,0,0,0,0);
464
- this.viewDate = new Date(year, month, day,0,0,0,0);
435
+ this.date = UTCDate(year, month, day,0,0,0,0);
436
+ this.viewDate = UTCDate(year, month, day,0,0,0,0);
465
437
  this.fill();
466
438
  this.setValue();
467
439
  this.element.trigger({
@@ -494,8 +466,8 @@
494
466
  moveMonth: function(date, dir){
495
467
  if (!dir) return date;
496
468
  var new_date = new Date(date.valueOf()),
497
- day = new_date.getDate(),
498
- month = new_date.getMonth(),
469
+ day = new_date.getUTCDate(),
470
+ month = new_date.getUTCMonth(),
499
471
  mag = Math.abs(dir),
500
472
  new_month, test;
501
473
  dir = dir > 0 ? 1 : -1;
@@ -503,12 +475,12 @@
503
475
  test = dir == -1
504
476
  // If going back one month, make sure month is not current month
505
477
  // (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02)
506
- ? function(){ return new_date.getMonth() == month; }
478
+ ? function(){ return new_date.getUTCMonth() == month; }
507
479
  // If going forward one month, make sure month is as expected
508
480
  // (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02)
509
- : function(){ return new_date.getMonth() != new_month; };
481
+ : function(){ return new_date.getUTCMonth() != new_month; };
510
482
  new_month = month + dir;
511
- new_date.setMonth(new_month);
483
+ new_date.setUTCMonth(new_month);
512
484
  // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11
513
485
  if (new_month < 0 || new_month > 11)
514
486
  new_month = (new_month + 12) % 12;
@@ -518,15 +490,15 @@
518
490
  // ...which might decrease the day (eg, Jan 31 to Feb 28, etc)...
519
491
  new_date = this.moveMonth(new_date, dir);
520
492
  // ...then reset the day, keeping it in the new month
521
- new_month = new_date.getMonth();
522
- new_date.setDate(day);
523
- test = function(){ return new_month != new_date.getMonth(); };
493
+ new_month = new_date.getUTCMonth();
494
+ new_date.setUTCDate(day);
495
+ test = function(){ return new_month != new_date.getUTCMonth(); };
524
496
  }
525
497
  // Common date-resetting loop -- if date is beyond end of month, make it
526
498
  // end of month
527
499
  while (test()){
528
- new_date.setDate(--day);
529
- new_date.setMonth(new_month);
500
+ new_date.setUTCDate(--day);
501
+ new_date.setUTCMonth(new_month);
530
502
  }
531
503
  return new_date;
532
504
  },
@@ -565,9 +537,9 @@
565
537
  newViewDate = this.moveMonth(this.viewDate, dir);
566
538
  } else {
567
539
  newDate = new Date(this.date);
568
- newDate.setDate(this.date.getDate() + dir);
540
+ newDate.setUTCDate(this.date.getUTCDate() + dir);
569
541
  newViewDate = new Date(this.viewDate);
570
- newViewDate.setDate(this.viewDate.getDate() + dir);
542
+ newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
571
543
  }
572
544
  if (this.dateWithinRange(newDate)){
573
545
  this.date = newDate;
@@ -590,9 +562,9 @@
590
562
  newViewDate = this.moveMonth(this.viewDate, dir);
591
563
  } else {
592
564
  newDate = new Date(this.date);
593
- newDate.setDate(this.date.getDate() + dir * 7);
565
+ newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
594
566
  newViewDate = new Date(this.viewDate);
595
- newViewDate.setDate(this.viewDate.getDate() + dir * 7);
567
+ newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
596
568
  }
597
569
  if (this.dateWithinRange(newDate)){
598
570
  this.date = newDate;
@@ -710,43 +682,43 @@
710
682
  dir = parseInt(part[1]);
711
683
  switch(part[2]){
712
684
  case 'd':
713
- date.setDate(date.getDate() + dir);
685
+ date.setUTCDate(date.getUTCDate() + dir);
714
686
  break;
715
687
  case 'm':
716
688
  date = Datepicker.prototype.moveMonth.call(Datepicker.prototype, date, dir);
717
689
  break;
718
690
  case 'w':
719
- date.setDate(date.getDate() + dir * 7);
691
+ date.setUTCDate(date.getUTCDate() + dir * 7);
720
692
  break;
721
693
  case 'y':
722
694
  date = Datepicker.prototype.moveYear.call(Datepicker.prototype, date, dir);
723
695
  break;
724
696
  }
725
697
  }
726
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
698
+ return UTCDate(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), 0, 0, 0);
727
699
  }
728
700
  var parts = date && date.match(this.nonpunctuation) || [],
729
701
  date = new Date(),
730
702
  parsed = {},
731
703
  setters_order = ['yyyy', 'yy', 'M', 'MM', 'm', 'mm', 'd', 'dd'],
732
704
  setters_map = {
733
- yyyy: function(d,v){ return d.setFullYear(v); },
734
- yy: function(d,v){ return d.setFullYear(2000+v); },
705
+ yyyy: function(d,v){ return d.setUTCFullYear(v); },
706
+ yy: function(d,v){ return d.setUTCFullYear(2000+v); },
735
707
  m: function(d,v){
736
708
  v -= 1;
737
709
  while (v<0) v += 12;
738
710
  v %= 12;
739
- d.setMonth(v);
740
- while (d.getMonth() != v)
741
- d.setDate(d.getDate()-1);
711
+ d.setUTCMonth(v);
712
+ while (d.getUTCMonth() != v)
713
+ d.setUTCDate(d.getUTCDate()-1);
742
714
  return d;
743
715
  },
744
- d: function(d,v){ return d.setDate(v); }
716
+ d: function(d,v){ return d.setUTCDate(v); }
745
717
  },
746
718
  val, filtered, part;
747
719
  setters_map['M'] = setters_map['MM'] = setters_map['mm'] = setters_map['m'];
748
720
  setters_map['dd'] = setters_map['d'];
749
- date = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
721
+ date = UTCDate(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), 0, 0, 0);
750
722
  if (parts.length == format.parts.length) {
751
723
  for (var i=0, cnt = format.parts.length; i < cnt; i++) {
752
724
  val = parseInt(parts[i], 10);
@@ -783,12 +755,12 @@
783
755
  },
784
756
  formatDate: function(date, format, language){
785
757
  var val = {
786
- d: date.getDate(),
787
- m: date.getMonth() + 1,
788
- M: dates[language].monthsShort[date.getMonth()],
789
- MM: dates[language].months[date.getMonth()],
790
- yy: date.getFullYear().toString().substring(2),
791
- yyyy: date.getFullYear()
758
+ d: date.getUTCDate(),
759
+ m: date.getUTCMonth() + 1,
760
+ M: dates[language].monthsShort[date.getUTCMonth()],
761
+ MM: dates[language].months[date.getUTCMonth()],
762
+ yy: date.getUTCFullYear().toString().substring(2),
763
+ yyyy: date.getUTCFullYear()
792
764
  };
793
765
  val.dd = (val.d < 10 ? '0' : '') + val.d;
794
766
  val.mm = (val.m < 10 ? '0' : '') + val.m;
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap-datepicker-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.16
4
+ version: 0.6.17
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-17 00:00:00.000000000 Z
12
+ date: 2012-08-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -118,7 +118,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
118
118
  version: '0'
119
119
  segments:
120
120
  - 0
121
- hash: 2327091248764895784
121
+ hash: 2859334882354847738
122
122
  required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  none: false
124
124
  requirements:
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
127
  version: '0'
128
128
  segments:
129
129
  - 0
130
- hash: 2327091248764895784
130
+ hash: 2859334882354847738
131
131
  requirements: []
132
132
  rubyforge_project:
133
133
  rubygems_version: 1.8.24