local_time 2.1.0 → 3.0.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.
metadata CHANGED
@@ -1,17 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: local_time
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javan Makhmali
8
8
  - Sam Stephenson
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-09-04 00:00:00.000000000 Z
13
- dependencies: []
14
- description:
12
+ date: 2024-01-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '13.0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '13.0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rails
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '7.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '7.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rails-dom-testing
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '2.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '2.0'
56
+ description:
15
57
  email: javan@basecamp.com
16
58
  executables: []
17
59
  extensions: []
@@ -19,24 +61,31 @@ extra_rdoc_files: []
19
61
  files:
20
62
  - MIT-LICENSE
21
63
  - README.md
22
- - app/assets/javascripts/local-time.js
64
+ - app/assets/javascripts/local-time.es2017-esm.js
65
+ - app/assets/javascripts/local-time.es2017-umd.js
23
66
  - app/helpers/local_time_helper.rb
24
67
  - lib/local_time.rb
68
+ - lib/local_time/version.rb
25
69
  - test/helpers/local_time_helper_test.rb
26
- - test/javascripts/fixtures/body.html
70
+ - test/javascripts/builds/index.js
71
+ - test/javascripts/fixtures/index.html
72
+ - test/javascripts/fixtures/time_zone_check.html
73
+ - test/javascripts/server.mjs
74
+ - test/javascripts/src/format24_test.coffee
27
75
  - test/javascripts/src/i18n_test.coffee
76
+ - test/javascripts/src/index.coffee
28
77
  - test/javascripts/src/local_time_test.coffee
29
78
  - test/javascripts/src/relative_date_test.coffee
30
79
  - test/javascripts/src/strftime_test.coffee
31
- - test/javascripts/src/test.coffee
80
+ - test/javascripts/src/test_helpers.coffee
32
81
  - test/javascripts/src/time_ago_test.coffee
33
82
  - test/javascripts/vendor/moment.js
34
- - test/javascripts/vendor/sinon-timers.js
35
- homepage:
83
+ - test/javascripts/vendor/sinon.js
84
+ homepage: https://github.com/basecamp/local_time
36
85
  licenses:
37
86
  - MIT
38
87
  metadata: {}
39
- post_install_message:
88
+ post_install_message:
40
89
  rdoc_options: []
41
90
  require_paths:
42
91
  - lib
@@ -51,19 +100,23 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
100
  - !ruby/object:Gem::Version
52
101
  version: '0'
53
102
  requirements: []
54
- rubyforge_project:
55
- rubygems_version: 2.7.6
56
- signing_key:
103
+ rubygems_version: 3.4.21
104
+ signing_key:
57
105
  specification_version: 4
58
106
  summary: Rails engine for cache-friendly, client-side local time
59
107
  test_files:
60
- - test/helpers/local_time_helper_test.rb
61
- - test/javascripts/fixtures/body.html
108
+ - test/javascripts/builds/index.js
109
+ - test/javascripts/server.mjs
110
+ - test/javascripts/fixtures/index.html
111
+ - test/javascripts/fixtures/time_zone_check.html
112
+ - test/javascripts/vendor/moment.js
113
+ - test/javascripts/vendor/sinon.js
114
+ - test/javascripts/src/strftime_test.coffee
115
+ - test/javascripts/src/index.coffee
62
116
  - test/javascripts/src/i18n_test.coffee
63
117
  - test/javascripts/src/local_time_test.coffee
64
- - test/javascripts/src/relative_date_test.coffee
65
- - test/javascripts/src/strftime_test.coffee
66
- - test/javascripts/src/test.coffee
67
118
  - test/javascripts/src/time_ago_test.coffee
68
- - test/javascripts/vendor/moment.js
69
- - test/javascripts/vendor/sinon-timers.js
119
+ - test/javascripts/src/format24_test.coffee
120
+ - test/javascripts/src/relative_date_test.coffee
121
+ - test/javascripts/src/test_helpers.coffee
122
+ - test/helpers/local_time_helper_test.rb
@@ -1 +0,0 @@
1
- (function(){var t=this;(function(){(function(){var t=[].slice;this.LocalTime={config:{},run:function(){return this.getController().processElements()},process:function(){var e,n,r,a;for(n=1<=arguments.length?t.call(arguments,0):[],r=0,a=n.length;r<a;r++)e=n[r],this.getController().processElement(e);return n.length},getController:function(){return null!=this.controller?this.controller:this.controller=new e.Controller}}}).call(this)}).call(t);var e=t.LocalTime;(function(){(function(){e.config.i18n={en:{date:{dayNames:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],abbrDayNames:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],monthNames:["January","February","March","April","May","June","July","August","September","October","November","December"],abbrMonthNames:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],yesterday:"yesterday",today:"today",tomorrow:"tomorrow",on:"on {date}",formats:{"default":"%b %e, %Y",thisYear:"%b %e"}},time:{am:"am",pm:"pm",singular:"a {time}",singularAn:"an {time}",elapsed:"{time} ago",second:"second",seconds:"seconds",minute:"minute",minutes:"minutes",hour:"hour",hours:"hours",formats:{"default":"%l:%M%P"}},datetime:{at:"{date} at {time}",formats:{"default":"%B %e, %Y at %l:%M%P %Z"}}}}}).call(this),function(){e.config.locale="en",e.config.defaultLocale="en"}.call(this),function(){e.config.timerInterval=6e4}.call(this),function(){var t,n,r;r=!isNaN(Date.parse("2011-01-01T12:00:00-05:00")),e.parseDate=function(t){return t=t.toString(),r||(t=n(t)),new Date(Date.parse(t))},t=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(Z|[-+]?[\d:]+)$/,n=function(e){var n,r,a,i,o,s,u,c,l;if(a=e.match(t))return a[0],c=a[1],o=a[2],n=a[3],r=a[4],i=a[5],u=a[6],l=a[7],"Z"!==l&&(s=l.replace(":","")),c+"/"+o+"/"+n+" "+r+":"+i+":"+u+" GMT"+[s]}}.call(this),function(){e.elementMatchesSelector=function(){var t,e,n,r,a,i;return t=document.documentElement,e=null!=(n=null!=(r=null!=(a=null!=(i=t.matches)?i:t.matchesSelector)?a:t.webkitMatchesSelector)?r:t.mozMatchesSelector)?n:t.msMatchesSelector,function(t,n){if((null!=t?t.nodeType:void 0)===Node.ELEMENT_NODE)return e.call(t,n)}}()}.call(this),function(){var t,n,r;t=e.config,r=t.i18n,e.getI18nValue=function(a,i){var o,s;return null==a&&(a=""),o=(null!=i?i:{locale:t.locale}).locale,s=n(r[o],a),null!=s?s:o!==t.defaultLocale?e.getI18nValue(a,{locale:t.defaultLocale}):void 0},e.translate=function(t,n,r){var a,i,o;null==n&&(n={}),o=e.getI18nValue(t,r);for(a in n)i=n[a],o=o.replace("{"+a+"}",i);return o},n=function(t,e){var n,r,a,i,o;for(o=t,i=e.split("."),n=0,a=i.length;n<a;n++){if(r=i[n],null==o[r])return null;o=o[r]}return o}}.call(this),function(){var t,n,r,a,i;t=e.getI18nValue,i=e.translate,e.strftime=a=function(e,o){var s,u,c,l,d,h,f;return u=e.getDay(),s=e.getDate(),d=e.getMonth(),f=e.getFullYear(),c=e.getHours(),l=e.getMinutes(),h=e.getSeconds(),o.replace(/%(-?)([%aAbBcdeHIlmMpPSwyYZ])/g,function(o,m,p){switch(p){case"%":return"%";case"a":return t("date.abbrDayNames")[u];case"A":return t("date.dayNames")[u];case"b":return t("date.abbrMonthNames")[d];case"B":return t("date.monthNames")[d];case"c":return e.toString();case"d":return n(s,m);case"e":return s;case"H":return n(c,m);case"I":return n(a(e,"%l"),m);case"l":return 0===c||12===c?12:(c+12)%12;case"m":return n(d+1,m);case"M":return n(l,m);case"p":return i("time."+(c>11?"pm":"am")).toUpperCase();case"P":return i("time."+(c>11?"pm":"am"));case"S":return n(h,m);case"w":return u;case"y":return n(f%100,m);case"Y":return f;case"Z":return r(e)}})},n=function(t,e){switch(e){case"-":return t;default:return("0"+t).slice(-2)}},r=function(t){var e,n,r,a,i;return i=t.toString(),(e=null!=(n=i.match(/\(([\w\s]+)\)$/))?n[1]:void 0)?/\s/.test(e)?e.match(/\b(\w)/g).join(""):e:(e=null!=(r=i.match(/(\w{3,4})\s\d{4}$/))?r[1]:void 0)?e:(e=null!=(a=i.match(/(UTC[\+\-]\d+)/))?a[1]:void 0)?e:""}}.call(this),function(){e.CalendarDate=function(){function t(t,e,n){this.date=new Date(Date.UTC(t,e-1)),this.date.setUTCDate(n),this.year=this.date.getUTCFullYear(),this.month=this.date.getUTCMonth()+1,this.day=this.date.getUTCDate(),this.value=this.date.getTime()}return t.fromDate=function(t){return new this(t.getFullYear(),t.getMonth()+1,t.getDate())},t.today=function(){return this.fromDate(new Date)},t.prototype.equals=function(t){return(null!=t?t.value:void 0)===this.value},t.prototype.is=function(t){return this.equals(t)},t.prototype.isToday=function(){return this.is(this.constructor.today())},t.prototype.occursOnSameYearAs=function(t){return this.year===(null!=t?t.year:void 0)},t.prototype.occursThisYear=function(){return this.occursOnSameYearAs(this.constructor.today())},t.prototype.daysSince=function(t){if(t)return(this.date-t.date)/864e5},t.prototype.daysPassed=function(){return this.constructor.today().daysSince(this)},t}()}.call(this),function(){var t,n,r;n=e.strftime,r=e.translate,t=e.getI18nValue,e.RelativeTime=function(){function a(t){this.date=t,this.calendarDate=e.CalendarDate.fromDate(this.date)}return a.prototype.toString=function(){var t,e;return(e=this.toTimeElapsedString())?r("time.elapsed",{time:e}):(t=this.toWeekdayString())?(e=this.toTimeString(),r("datetime.at",{date:t,time:e})):r("date.on",{date:this.toDateString()})},a.prototype.toTimeOrDateString=function(){return this.calendarDate.isToday()?this.toTimeString():this.toDateString()},a.prototype.toTimeElapsedString=function(){var t,e,n,a,i;return n=(new Date).getTime()-this.date.getTime(),a=Math.round(n/1e3),e=Math.round(a/60),t=Math.round(e/60),n<0?null:a<10?(i=r("time.second"),r("time.singular",{time:i})):a<45?a+" "+r("time.seconds"):a<90?(i=r("time.minute"),r("time.singular",{time:i})):e<45?e+" "+r("time.minutes"):e<90?(i=r("time.hour"),r("time.singularAn",{time:i})):t<24?t+" "+r("time.hours"):""},a.prototype.toWeekdayString=function(){switch(this.calendarDate.daysPassed()){case 0:return r("date.today");case 1:return r("date.yesterday");case-1:return r("date.tomorrow");case 2:case 3:case 4:case 5:case 6:return n(this.date,"%A");default:return""}},a.prototype.toDateString=function(){var e;return e=t(this.calendarDate.occursThisYear()?"date.formats.thisYear":"date.formats.default"),n(this.date,e)},a.prototype.toTimeString=function(){return n(this.date,t("time.formats.default"))},a}()}.call(this),function(){var t,n=function(t,e){return function(){return t.apply(e,arguments)}};t=e.elementMatchesSelector,e.PageObserver=function(){function e(t,e){this.selector=t,this.callback=e,this.processInsertion=n(this.processInsertion,this),this.processMutations=n(this.processMutations,this)}return e.prototype.start=function(){if(!this.started)return this.observeWithMutationObserver()||this.observeWithMutationEvent(),this.started=!0},e.prototype.observeWithMutationObserver=function(){var t;if("undefined"!=typeof MutationObserver&&null!==MutationObserver)return t=new MutationObserver(this.processMutations),t.observe(document.documentElement,{childList:!0,subtree:!0}),!0},e.prototype.observeWithMutationEvent=function(){return addEventListener("DOMNodeInserted",this.processInsertion,!1),!0},e.prototype.findSignificantElements=function(e){var n;return n=[],(null!=e?e.nodeType:void 0)===Node.ELEMENT_NODE&&(t(e,this.selector)&&n.push(e),n.push.apply(n,e.querySelectorAll(this.selector))),n},e.prototype.processMutations=function(t){var e,n,r,a,i,o,s,u;for(e=[],n=0,a=t.length;n<a;n++)switch(o=t[n],o.type){case"childList":for(u=o.addedNodes,r=0,i=u.length;r<i;r++)s=u[r],e.push.apply(e,this.findSignificantElements(s))}return this.notify(e)},e.prototype.processInsertion=function(t){var e;return e=this.findSignificantElements(t.target),this.notify(e)},e.prototype.notify=function(t){if(null!=t?t.length:void 0)return"function"==typeof this.callback?this.callback(t):void 0},e}()}.call(this),function(){var t,n,r,a,i=function(t,e){return function(){return t.apply(e,arguments)}};r=e.parseDate,a=e.strftime,n=e.getI18nValue,t=e.config,e.Controller=function(){function o(){this.processElements=i(this.processElements,this),this.pageObserver=new e.PageObserver(s,this.processElements)}var s,u,c;return s="time[data-local]:not([data-localized])",o.prototype.start=function(){if(!this.started)return this.processElements(),this.startTimer(),this.pageObserver.start(),this.started=!0},o.prototype.startTimer=function(){var e;if(e=t.timerInterval)return null!=this.timer?this.timer:this.timer=setInterval(this.processElements,e)},o.prototype.processElements=function(t){var e,n,r;for(null==t&&(t=document.querySelectorAll(s)),n=0,r=t.length;n<r;n++)e=t[n],this.processElement(e);return t.length},o.prototype.processElement=function(t){var e,i,o,s,l,d;if(i=t.getAttribute("datetime"),o=t.getAttribute("data-format"),s=t.getAttribute("data-local"),l=r(i),!isNaN(l))return t.hasAttribute("title")||(d=a(l,n("datetime.formats.default")),t.setAttribute("title",d)),t.textContent=e=function(){switch(s){case"time":return u(t),a(l,o);case"date":return u(t),c(l).toDateString();case"time-ago":return c(l).toString();case"time-or-date":return c(l).toTimeOrDateString();case"weekday":return c(l).toWeekdayString();case"weekday-or-date":return c(l).toWeekdayString()||c(l).toDateString()}}(),t.hasAttribute("aria-label")?void 0:t.setAttribute("aria-label",e)},u=function(t){return t.setAttribute("data-localized","")},c=function(t){return new e.RelativeTime(t)},o}()}.call(this),function(){var t,n,r,a;a=!1,t=function(){return document.attachEvent?"complete"===document.readyState:"loading"!==document.readyState},n=function(t){var e;return null!=(e="function"==typeof requestAnimationFrame?requestAnimationFrame(t):void 0)?e:setTimeout(t,17)},r=function(){var t;return t=e.getController(),t.start()},e.start=function(){if(!a)return a=!0,"undefined"!=typeof MutationObserver&&null!==MutationObserver||t()?r():n(r)},window.LocalTime===e&&e.start()}.call(this)}).call(this),"object"==typeof module&&module.exports?module.exports=e:"function"==typeof define&&define.amd&&define(e)}).call(this);
@@ -1,8 +0,0 @@
1
- <time id="one" data-format="%B %e, %Y %l:%M%P" data-local="time" datetime="2013-11-12T12:13:00Z"></time>
2
- <time id="two" data-format="%B %e, %Y %l:%M%P" data-local="time" datetime="2013-01-02T02:04:00Z"></time>
3
- <time id="past" data-format="%B %e, %Y %l:%M%P" data-local="time" datetime="1805-05-15T01:01:00Z"></time>
4
- <time id="future" data-format="%B %e, %Y %l:%M%P" data-local="time" datetime="3333-02-14T23:55:00Z"></time>
5
-
6
- <time id="date" data-format="%B %e, %Y" data-local="time" datetime="2013-11-12T12:13:00Z"></time>
7
-
8
- <time id="ago"></time>
@@ -1,385 +0,0 @@
1
- /**
2
- * Sinon.JS 1.7.1, 2013/05/07
3
- *
4
- * @author Christian Johansen (christian@cjohansen.no)
5
- * @author Contributors: https://github.com/cjohansen/Sinon.JS/blob/master/AUTHORS
6
- *
7
- * (The BSD License)
8
- *
9
- * Copyright (c) 2010-2013, Christian Johansen, christian@cjohansen.no
10
- * All rights reserved.
11
- *
12
- * Redistribution and use in source and binary forms, with or without modification,
13
- * are permitted provided that the following conditions are met:
14
- *
15
- * * Redistributions of source code must retain the above copyright notice,
16
- * this list of conditions and the following disclaimer.
17
- * * Redistributions in binary form must reproduce the above copyright notice,
18
- * this list of conditions and the following disclaimer in the documentation
19
- * and/or other materials provided with the distribution.
20
- * * Neither the name of Christian Johansen nor the names of his contributors
21
- * may be used to endorse or promote products derived from this software
22
- * without specific prior written permission.
23
- *
24
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
- */
35
-
36
- /*jslint eqeqeq: false, plusplus: false, evil: true, onevar: false, browser: true, forin: false*/
37
- /*global module, require, window*/
38
- /**
39
- * Fake timer API
40
- * setTimeout
41
- * setInterval
42
- * clearTimeout
43
- * clearInterval
44
- * tick
45
- * reset
46
- * Date
47
- *
48
- * Inspired by jsUnitMockTimeOut from JsUnit
49
- *
50
- * @author Christian Johansen (christian@cjohansen.no)
51
- * @license BSD
52
- *
53
- * Copyright (c) 2010-2013 Christian Johansen
54
- */
55
-
56
- if (typeof sinon == "undefined") {
57
- var sinon = {};
58
- }
59
-
60
- (function (global) {
61
- var id = 1;
62
-
63
- function addTimer(args, recurring) {
64
- if (args.length === 0) {
65
- throw new Error("Function requires at least 1 parameter");
66
- }
67
-
68
- var toId = id++;
69
- var delay = args[1] || 0;
70
-
71
- if (!this.timeouts) {
72
- this.timeouts = {};
73
- }
74
-
75
- this.timeouts[toId] = {
76
- id: toId,
77
- func: args[0],
78
- callAt: this.now + delay,
79
- invokeArgs: Array.prototype.slice.call(args, 2)
80
- };
81
-
82
- if (recurring === true) {
83
- this.timeouts[toId].interval = delay;
84
- }
85
-
86
- return toId;
87
- }
88
-
89
- function parseTime(str) {
90
- if (!str) {
91
- return 0;
92
- }
93
-
94
- var strings = str.split(":");
95
- var l = strings.length, i = l;
96
- var ms = 0, parsed;
97
-
98
- if (l > 3 || !/^(\d\d:){0,2}\d\d?$/.test(str)) {
99
- throw new Error("tick only understands numbers and 'h:m:s'");
100
- }
101
-
102
- while (i--) {
103
- parsed = parseInt(strings[i], 10);
104
-
105
- if (parsed >= 60) {
106
- throw new Error("Invalid time " + str);
107
- }
108
-
109
- ms += parsed * Math.pow(60, (l - i - 1));
110
- }
111
-
112
- return ms * 1000;
113
- }
114
-
115
- function createObject(object) {
116
- var newObject;
117
-
118
- if (Object.create) {
119
- newObject = Object.create(object);
120
- } else {
121
- var F = function () {};
122
- F.prototype = object;
123
- newObject = new F();
124
- }
125
-
126
- newObject.Date.clock = newObject;
127
- return newObject;
128
- }
129
-
130
- sinon.clock = {
131
- now: 0,
132
-
133
- create: function create(now) {
134
- var clock = createObject(this);
135
-
136
- if (typeof now == "number") {
137
- clock.now = now;
138
- }
139
-
140
- if (!!now && typeof now == "object") {
141
- throw new TypeError("now should be milliseconds since UNIX epoch");
142
- }
143
-
144
- return clock;
145
- },
146
-
147
- setTimeout: function setTimeout(callback, timeout) {
148
- return addTimer.call(this, arguments, false);
149
- },
150
-
151
- clearTimeout: function clearTimeout(timerId) {
152
- if (!this.timeouts) {
153
- this.timeouts = [];
154
- }
155
-
156
- if (timerId in this.timeouts) {
157
- delete this.timeouts[timerId];
158
- }
159
- },
160
-
161
- setInterval: function setInterval(callback, timeout) {
162
- return addTimer.call(this, arguments, true);
163
- },
164
-
165
- clearInterval: function clearInterval(timerId) {
166
- this.clearTimeout(timerId);
167
- },
168
-
169
- tick: function tick(ms) {
170
- ms = typeof ms == "number" ? ms : parseTime(ms);
171
- var tickFrom = this.now, tickTo = this.now + ms, previous = this.now;
172
- var timer = this.firstTimerInRange(tickFrom, tickTo);
173
-
174
- var firstException;
175
- while (timer && tickFrom <= tickTo) {
176
- if (this.timeouts[timer.id]) {
177
- tickFrom = this.now = timer.callAt;
178
- try {
179
- this.callTimer(timer);
180
- } catch (e) {
181
- firstException = firstException || e;
182
- }
183
- }
184
-
185
- timer = this.firstTimerInRange(previous, tickTo);
186
- previous = tickFrom;
187
- }
188
-
189
- this.now = tickTo;
190
-
191
- if (firstException) {
192
- throw firstException;
193
- }
194
-
195
- return this.now;
196
- },
197
-
198
- firstTimerInRange: function (from, to) {
199
- var timer, smallest, originalTimer;
200
-
201
- for (var id in this.timeouts) {
202
- if (this.timeouts.hasOwnProperty(id)) {
203
- if (this.timeouts[id].callAt < from || this.timeouts[id].callAt > to) {
204
- continue;
205
- }
206
-
207
- if (!smallest || this.timeouts[id].callAt < smallest) {
208
- originalTimer = this.timeouts[id];
209
- smallest = this.timeouts[id].callAt;
210
-
211
- timer = {
212
- func: this.timeouts[id].func,
213
- callAt: this.timeouts[id].callAt,
214
- interval: this.timeouts[id].interval,
215
- id: this.timeouts[id].id,
216
- invokeArgs: this.timeouts[id].invokeArgs
217
- };
218
- }
219
- }
220
- }
221
-
222
- return timer || null;
223
- },
224
-
225
- callTimer: function (timer) {
226
- if (typeof timer.interval == "number") {
227
- this.timeouts[timer.id].callAt += timer.interval;
228
- } else {
229
- delete this.timeouts[timer.id];
230
- }
231
-
232
- try {
233
- if (typeof timer.func == "function") {
234
- timer.func.apply(null, timer.invokeArgs);
235
- } else {
236
- eval(timer.func);
237
- }
238
- } catch (e) {
239
- var exception = e;
240
- }
241
-
242
- if (!this.timeouts[timer.id]) {
243
- if (exception) {
244
- throw exception;
245
- }
246
- return;
247
- }
248
-
249
- if (exception) {
250
- throw exception;
251
- }
252
- },
253
-
254
- reset: function reset() {
255
- this.timeouts = {};
256
- },
257
-
258
- Date: (function () {
259
- var NativeDate = Date;
260
-
261
- function ClockDate(year, month, date, hour, minute, second, ms) {
262
- // Defensive and verbose to avoid potential harm in passing
263
- // explicit undefined when user does not pass argument
264
- switch (arguments.length) {
265
- case 0:
266
- return new NativeDate(ClockDate.clock.now);
267
- case 1:
268
- return new NativeDate(year);
269
- case 2:
270
- return new NativeDate(year, month);
271
- case 3:
272
- return new NativeDate(year, month, date);
273
- case 4:
274
- return new NativeDate(year, month, date, hour);
275
- case 5:
276
- return new NativeDate(year, month, date, hour, minute);
277
- case 6:
278
- return new NativeDate(year, month, date, hour, minute, second);
279
- default:
280
- return new NativeDate(year, month, date, hour, minute, second, ms);
281
- }
282
- }
283
-
284
- return mirrorDateProperties(ClockDate, NativeDate);
285
- }())
286
- };
287
-
288
- function mirrorDateProperties(target, source) {
289
- if (source.now) {
290
- target.now = function now() {
291
- return target.clock.now;
292
- };
293
- } else {
294
- delete target.now;
295
- }
296
-
297
- if (source.toSource) {
298
- target.toSource = function toSource() {
299
- return source.toSource();
300
- };
301
- } else {
302
- delete target.toSource;
303
- }
304
-
305
- target.toString = function toString() {
306
- return source.toString();
307
- };
308
-
309
- target.prototype = source.prototype;
310
- target.parse = source.parse;
311
- target.UTC = source.UTC;
312
- target.prototype.toUTCString = source.prototype.toUTCString;
313
- return target;
314
- }
315
-
316
- var methods = ["Date", "setTimeout", "setInterval",
317
- "clearTimeout", "clearInterval"];
318
-
319
- function restore() {
320
- var method;
321
-
322
- for (var i = 0, l = this.methods.length; i < l; i++) {
323
- method = this.methods[i];
324
- if (global[method].hadOwnProperty) {
325
- global[method] = this["_" + method];
326
- } else {
327
- delete global[method];
328
- }
329
- }
330
-
331
- // Prevent multiple executions which will completely remove these props
332
- this.methods = [];
333
- }
334
-
335
- function stubGlobal(method, clock) {
336
- clock[method].hadOwnProperty = Object.prototype.hasOwnProperty.call(global, method);
337
- clock["_" + method] = global[method];
338
-
339
- if (method == "Date") {
340
- var date = mirrorDateProperties(clock[method], global[method]);
341
- global[method] = date;
342
- } else {
343
- global[method] = function () {
344
- return clock[method].apply(clock, arguments);
345
- };
346
-
347
- for (var prop in clock[method]) {
348
- if (clock[method].hasOwnProperty(prop)) {
349
- global[method][prop] = clock[method][prop];
350
- }
351
- }
352
- }
353
-
354
- global[method].clock = clock;
355
- }
356
-
357
- sinon.useFakeTimers = function useFakeTimers(now) {
358
- var clock = sinon.clock.create(now);
359
- clock.restore = restore;
360
- clock.methods = Array.prototype.slice.call(arguments,
361
- typeof now == "number" ? 1 : 0);
362
-
363
- if (clock.methods.length === 0) {
364
- clock.methods = methods;
365
- }
366
-
367
- for (var i = 0, l = clock.methods.length; i < l; i++) {
368
- stubGlobal(clock.methods[i], clock);
369
- }
370
-
371
- return clock;
372
- };
373
- }(typeof global != "undefined" && typeof global !== "function" ? global : this));
374
-
375
- sinon.timers = {
376
- setTimeout: setTimeout,
377
- clearTimeout: clearTimeout,
378
- setInterval: setInterval,
379
- clearInterval: clearInterval,
380
- Date: Date
381
- };
382
-
383
- if (typeof module == "object" && typeof require == "function") {
384
- module.exports = sinon;
385
- }