input_calendar 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  module InputCalendar
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
data/src/calendar.coffee CHANGED
@@ -30,10 +30,7 @@ class @Calendar
30
30
  # should override this in a subclass if you're date string looks different
31
31
  parseIncomingDate: () ->
32
32
  # cut off the time part of the date element
33
- date=@field.val().split(" ")[0]
34
- [year, month, day] = _.map(date.split("-"), (x) ->
35
- parseInt x.replace /^0/, "")
36
- new Date(year, month-1, day)
33
+ @parseDateYMD(@field.val().split(" ")[0])
37
34
 
38
35
  show: () -> @element.show()
39
36
  hide: () -> @element.hide()
@@ -102,17 +99,20 @@ class @Calendar
102
99
  "<td class='#{classes.join(" ")}'><a data-date='#{@toDateString(date)}' href='#'>#{date.getDate()}</a></td>"
103
100
 
104
101
  toDateString: (date) ->
105
- month = date.getMonth()
102
+ month = date.getMonth() + 1
106
103
  day = date.getDate()
107
104
  month = if month < 10 then "0#{month}" else month
108
105
  day = if day < 10 then "0#{day}" else day
109
106
  "#{date.getFullYear()}-#{month}-#{day}"
107
+
108
+ parseDateYMD: (ymd) ->
109
+ args = ymd.split("-")
110
+ new Date(args[0], parseInt(args[1],10)-1, parseInt(args[2],10))
110
111
 
111
112
  clicked: (event) ->
112
113
  o=$(event.target)
113
114
  o=o.children("A") if o[0].tagName=="TD"
114
- args = o.data("date").split("-")
115
- @date = new Date(args[0], args[1], args[2])
115
+ @date = @parseDateYMD(o.data("date"))
116
116
  # stuff the raw value in the value field
117
117
  @field.val(o.data("date"))
118
118
  @element.find(".selected").removeClass "selected"
@@ -44,12 +44,7 @@
44
44
  };
45
45
 
46
46
  Calendar.prototype.parseIncomingDate = function() {
47
- var date, day, month, year, _ref;
48
- date = this.field.val().split(" ")[0];
49
- _ref = _.map(date.split("-"), function(x) {
50
- return parseInt(x.replace(/^0/, ""));
51
- }), year = _ref[0], month = _ref[1], day = _ref[2];
52
- return new Date(year, month - 1, day);
47
+ return this.parseDateYMD(this.field.val().split(" ")[0]);
53
48
  };
54
49
 
55
50
  Calendar.prototype.show = function() {
@@ -182,21 +177,26 @@
182
177
 
183
178
  Calendar.prototype.toDateString = function(date) {
184
179
  var day, month;
185
- month = date.getMonth();
180
+ month = date.getMonth() + 1;
186
181
  day = date.getDate();
187
182
  month = month < 10 ? "0" + month : month;
188
183
  day = day < 10 ? "0" + day : day;
189
184
  return "" + (date.getFullYear()) + "-" + month + "-" + day;
190
185
  };
191
186
 
187
+ Calendar.prototype.parseDateYMD = function(ymd) {
188
+ var args;
189
+ args = ymd.split("-");
190
+ return new Date(args[0], parseInt(args[1], 10) - 1, parseInt(args[2], 10));
191
+ };
192
+
192
193
  Calendar.prototype.clicked = function(event) {
193
- var args, o;
194
+ var o;
194
195
  o = $(event.target);
195
196
  if (o[0].tagName === "TD") {
196
197
  o = o.children("A");
197
198
  }
198
- args = o.data("date").split("-");
199
- this.date = new Date(args[0], args[1], args[2]);
199
+ this.date = this.parseDateYMD(o.data("date"));
200
200
  this.field.val(o.data("date"));
201
201
  this.element.find(".selected").removeClass("selected");
202
202
  o.parent().addClass("selected");
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: input_calendar
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
9
+ - 2
10
+ version: 0.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Josh Goebel