timespan 0.5.2 → 0.5.3

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.
@@ -0,0 +1,83 @@
1
+ Date.create = function(p_Date, format){
2
+ var dateFormat = dateFormat || "DD/MM/YYYY";
3
+ if (jQuery.type(p_Date) === 'string') {
4
+ var secs = moment(p_Date, dateFormat).valueOf();
5
+ return new Date(secs);
6
+ }
7
+ return p_Date;
8
+ }
9
+
10
+ Date.timeleft = function(fromDate, toDate){
11
+ var now = Date.create(fromDate);
12
+ var end = Date.create(toDate);
13
+
14
+ if(now >= end){
15
+ [now, end] = [end, now]
16
+ }
17
+
18
+ yr = now.getYear();
19
+ if(now.getYear() < 1900)
20
+ yr = now.getYear() + 1900;
21
+
22
+ var dy = end.getDate() - now.getDate();
23
+ var mnth = end.getMonth() - now.getMonth();
24
+ var yr = end.getFullYear() - yr;
25
+ var daysinmnth = 32 - new Date(now.getYear(),now.getMonth(), 32).getDate();
26
+
27
+ if(dy < 0){
28
+ dy = (dy+daysinmnth)%daysinmnth;
29
+ mnth--;
30
+ }
31
+ if(mnth < 0){
32
+ mnth = (mnth+12)%12;
33
+ yr--;
34
+ }
35
+
36
+ var wk = 0;
37
+ if(dy > 7){
38
+ wk = Math.floor(dy / 7);
39
+ dy = dy % 7;
40
+ }
41
+
42
+ return Date.formatDuration(yr, mnth, wk, dy);
43
+ }
44
+ Date.period = Date.timeleft;
45
+ Date.duration = Date.timeleft;
46
+ Date.timespan = Date.timeleft;
47
+
48
+
49
+ String.prototype.formatStr = function() {
50
+ var formatted = this;
51
+ for (var i = 0; i < arguments.length; i++) {
52
+ var regexp = new RegExp('\\{'+i+'\\}', 'gi');
53
+ formatted = formatted.replace(regexp, arguments[i]);
54
+ }
55
+ return formatted;
56
+ };
57
+
58
+ Date.formatDuration = function(years, months, weeks, days) {
59
+
60
+ var pluralis = function(number, unit) {
61
+ if (number == 1)
62
+ return number.toString() + ' ' + unit;
63
+ return number.toString() + ' ' + unit + 's';
64
+ }
65
+
66
+ var list = [];
67
+
68
+ // TODO: support localization!
69
+ if (years > 1)
70
+ list.push(pluralis(years, 'year'));
71
+ if (months > 0)
72
+ list.push(pluralis(months, 'month'));
73
+ if (weeks > 0)
74
+ list.push(pluralis(weeks, 'week'));
75
+ if (days > 0)
76
+ list.push(pluralis(days, 'day'));
77
+
78
+ var lastPartStr = list[list.length - 1];
79
+ var parts = list.slice(0, list.length -1);
80
+ var partStr = parts.join(', ');
81
+
82
+ return parts.length == 0 ? lastPartStr : (partStr + ' and ' + lastPartStr);
83
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timespan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
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-11-19 00:00:00.000000000 Z
12
+ date: 2012-12-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chronic
@@ -290,6 +290,9 @@ files:
290
290
  - spec/timespan_init_spec.rb
291
291
  - spec/timespan_spec.rb
292
292
  - timespan.gemspec
293
+ - vendor/assets/javascripts/date_ext.js
294
+ - vendor/assets/javascripts/moment.js
295
+ - vendor/assets/javascripts/timespan.js
293
296
  homepage: http://github.com/kristianmandrup/timespan
294
297
  licenses:
295
298
  - MIT
@@ -305,7 +308,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
305
308
  version: '0'
306
309
  segments:
307
310
  - 0
308
- hash: 4516363936943259477
311
+ hash: -1354784355607378735
309
312
  required_rubygems_version: !ruby/object:Gem::Requirement
310
313
  none: false
311
314
  requirements: