local_time 2.1.0 → 3.0.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.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +50 -10
- data/app/assets/javascripts/local-time.es2017-esm.js +1 -0
- data/app/assets/javascripts/local-time.es2017-umd.js +1 -0
- data/app/helpers/local_time_helper.rb +72 -21
- data/lib/local_time/version.rb +3 -0
- data/test/helpers/local_time_helper_test.rb +60 -31
- data/test/javascripts/builds/index.js +26626 -0
- data/test/javascripts/fixtures/index.html +20 -0
- data/test/javascripts/fixtures/time_zone_check.html +20 -0
- data/test/javascripts/server.mjs +41 -0
- data/test/javascripts/src/format24_test.js +109 -0
- data/test/javascripts/src/i18n_test.js +55 -0
- data/test/javascripts/src/index.js +10 -0
- data/test/javascripts/src/local_time_test.js +54 -0
- data/test/javascripts/src/relative_date_test.js +121 -0
- data/test/javascripts/src/strftime_test.js +151 -0
- data/test/javascripts/src/test_helpers.js +66 -0
- data/test/javascripts/src/time_ago_test.js +72 -0
- data/test/javascripts/vendor/moment.js +5684 -2
- data/test/javascripts/vendor/sinon.js +20485 -0
- metadata +81 -28
- data/app/assets/javascripts/local-time.js +0 -1
- data/test/javascripts/fixtures/body.html +0 -8
- data/test/javascripts/src/i18n_test.coffee +0 -47
- data/test/javascripts/src/local_time_test.coffee +0 -37
- data/test/javascripts/src/relative_date_test.coffee +0 -89
- data/test/javascripts/src/strftime_test.coffee +0 -54
- data/test/javascripts/src/test.coffee +0 -43
- data/test/javascripts/src/time_ago_test.coffee +0 -56
- data/test/javascripts/vendor/sinon-timers.js +0 -385
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:
|
4
|
+
version: 3.0.3
|
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:
|
13
|
-
dependencies:
|
14
|
-
|
12
|
+
date: 2025-03-13 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/
|
27
|
-
- test/javascripts/
|
28
|
-
- test/javascripts/
|
29
|
-
- test/javascripts/
|
30
|
-
- test/javascripts/src/
|
31
|
-
- test/javascripts/src/
|
32
|
-
- test/javascripts/src/
|
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.js
|
75
|
+
- test/javascripts/src/i18n_test.js
|
76
|
+
- test/javascripts/src/index.js
|
77
|
+
- test/javascripts/src/local_time_test.js
|
78
|
+
- test/javascripts/src/relative_date_test.js
|
79
|
+
- test/javascripts/src/strftime_test.js
|
80
|
+
- test/javascripts/src/test_helpers.js
|
81
|
+
- test/javascripts/src/time_ago_test.js
|
33
82
|
- test/javascripts/vendor/moment.js
|
34
|
-
- test/javascripts/vendor/sinon
|
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
|
-
|
55
|
-
|
56
|
-
signing_key:
|
103
|
+
rubygems_version: 3.1.6
|
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/
|
61
|
-
- test/javascripts/
|
62
|
-
- test/javascripts/
|
63
|
-
- 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
|
-
- test/javascripts/src/time_ago_test.coffee
|
108
|
+
- test/javascripts/server.mjs
|
109
|
+
- test/javascripts/builds/index.js
|
110
|
+
- test/javascripts/vendor/sinon.js
|
68
111
|
- test/javascripts/vendor/moment.js
|
69
|
-
- test/javascripts/
|
112
|
+
- test/javascripts/src/local_time_test.js
|
113
|
+
- test/javascripts/src/time_ago_test.js
|
114
|
+
- test/javascripts/src/i18n_test.js
|
115
|
+
- test/javascripts/src/strftime_test.js
|
116
|
+
- test/javascripts/src/format24_test.js
|
117
|
+
- test/javascripts/src/test_helpers.js
|
118
|
+
- test/javascripts/src/relative_date_test.js
|
119
|
+
- test/javascripts/src/index.js
|
120
|
+
- test/javascripts/fixtures/time_zone_check.html
|
121
|
+
- test/javascripts/fixtures/index.html
|
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,47 +0,0 @@
|
|
1
|
-
{addTimeEl, assert, defer, getText, setText, test, testAsync, testGroup, triggerEvent} = LocalTime.TestHelpers
|
2
|
-
{config} = LocalTime
|
3
|
-
{i18n} = config
|
4
|
-
|
5
|
-
testGroup "i18n", ->
|
6
|
-
testAsync "updating a value", (done) ->
|
7
|
-
now = moment()
|
8
|
-
values = i18n[config.defaultLocale].date
|
9
|
-
|
10
|
-
originalValue = values.today
|
11
|
-
values.today = "2day"
|
12
|
-
|
13
|
-
el = addTimeEl type: "weekday", datetime: now.toISOString()
|
14
|
-
defer ->
|
15
|
-
assert.equal getText(el), "2day"
|
16
|
-
assert.equal getText(el), "2day"
|
17
|
-
values.today = originalValue
|
18
|
-
done()
|
19
|
-
|
20
|
-
testAsync "adding a new locale", (done) ->
|
21
|
-
now = moment()
|
22
|
-
|
23
|
-
originalLocale = config.locale
|
24
|
-
config.locale = "es"
|
25
|
-
i18n.es = date: today: "hoy"
|
26
|
-
|
27
|
-
el = addTimeEl type: "weekday", datetime: now.toISOString()
|
28
|
-
defer ->
|
29
|
-
assert.equal getText(el), "hoy"
|
30
|
-
config.locale = originalLocale
|
31
|
-
done()
|
32
|
-
|
33
|
-
testAsync "falling back to the default locale", (done) ->
|
34
|
-
now = moment()
|
35
|
-
yesterday = moment().subtract("days", 1)
|
36
|
-
|
37
|
-
originalLocale = config.locale
|
38
|
-
config.locale = "es"
|
39
|
-
i18n.es = date: yesterday: "ayer"
|
40
|
-
|
41
|
-
elWithTranslation = addTimeEl type: "weekday", datetime: yesterday.toISOString()
|
42
|
-
elWithoutTranslation = addTimeEl type: "weekday", datetime: now.toISOString()
|
43
|
-
defer ->
|
44
|
-
assert.equal getText(elWithTranslation), "ayer"
|
45
|
-
assert.equal getText(elWithoutTranslation), "today"
|
46
|
-
config.locale = originalLocale
|
47
|
-
done()
|
@@ -1,37 +0,0 @@
|
|
1
|
-
{addTimeEl, assert, defer, getText, setText, test, testAsync, testGroup, triggerEvent} = LocalTime.TestHelpers
|
2
|
-
|
3
|
-
testGroup "localized", ->
|
4
|
-
for id in ["one", "two", "past", "future"]
|
5
|
-
test id, ->
|
6
|
-
assertLocalized id
|
7
|
-
|
8
|
-
test "date", ->
|
9
|
-
assertLocalized "date", "date"
|
10
|
-
|
11
|
-
test "unparseable time", ->
|
12
|
-
el = addTimeEl format: "%Y", datetime: ":("
|
13
|
-
setText el, "2013"
|
14
|
-
assert.equal getText(el), "2013"
|
15
|
-
|
16
|
-
|
17
|
-
assertLocalized = (id, type = "time") ->
|
18
|
-
switch type
|
19
|
-
when "time"
|
20
|
-
momentFormat = "MMMM D, YYYY h:mma"
|
21
|
-
compare = "toString"
|
22
|
-
when "date"
|
23
|
-
momentFormat = "MMMM D, YYYY"
|
24
|
-
compare = "dayOfYear"
|
25
|
-
|
26
|
-
el = document.getElementById id
|
27
|
-
|
28
|
-
assert.ok datetime = el.getAttribute "datetime"
|
29
|
-
assert.ok local = getText el
|
30
|
-
assert.equal el.getAttribute("aria-label"), local
|
31
|
-
|
32
|
-
datetimeParsed = moment datetime
|
33
|
-
localParsed = moment local, momentFormat
|
34
|
-
|
35
|
-
assert.ok datetimeParsed.isValid()
|
36
|
-
assert.ok localParsed.isValid()
|
37
|
-
assert.equal datetimeParsed[compare](), localParsed[compare]()
|
@@ -1,89 +0,0 @@
|
|
1
|
-
{addTimeEl, assert, defer, getText, setText, test, testAsync, testGroup, triggerEvent} = LocalTime.TestHelpers
|
2
|
-
|
3
|
-
testGroup "relative date", ->
|
4
|
-
testAsync "this year", (done) ->
|
5
|
-
now = moment()
|
6
|
-
el = addTimeEl type: "date", datetime: now.toISOString()
|
7
|
-
defer ->
|
8
|
-
assert.equal getText(el), now.format("MMM D")
|
9
|
-
done()
|
10
|
-
|
11
|
-
testAsync "last year", (done) ->
|
12
|
-
before = moment().subtract("years", 1).subtract("days", 1)
|
13
|
-
el = addTimeEl type: "date", datetime: before.toISOString()
|
14
|
-
defer ->
|
15
|
-
assert.equal getText(el), before.format("MMM D, YYYY")
|
16
|
-
done()
|
17
|
-
|
18
|
-
testGroup "relative time or date", ->
|
19
|
-
testAsync "today", (done) ->
|
20
|
-
now = moment()
|
21
|
-
el = addTimeEl type: "time-or-date", datetime: now.toISOString()
|
22
|
-
defer ->
|
23
|
-
assert.equal getText(el), now.format("h:mma")
|
24
|
-
done()
|
25
|
-
|
26
|
-
testAsync "before today", (done) ->
|
27
|
-
before = moment().subtract("days", 1)
|
28
|
-
el = addTimeEl type: "time-or-date", datetime: before.toISOString()
|
29
|
-
defer ->
|
30
|
-
assert.equal getText(el), before.format("MMM D")
|
31
|
-
done()
|
32
|
-
|
33
|
-
testGroup "relative weekday", ->
|
34
|
-
testAsync "today", (done) ->
|
35
|
-
now = moment()
|
36
|
-
el = addTimeEl type: "weekday", datetime: now.toISOString()
|
37
|
-
defer ->
|
38
|
-
assert.equal getText(el), "today"
|
39
|
-
done()
|
40
|
-
|
41
|
-
testAsync "yesterday", (done) ->
|
42
|
-
yesterday = moment().subtract("days", 1)
|
43
|
-
el = addTimeEl type: "weekday", datetime: yesterday.toISOString()
|
44
|
-
defer ->
|
45
|
-
assert.equal getText(el), "yesterday"
|
46
|
-
done()
|
47
|
-
|
48
|
-
testAsync "this week", (done) ->
|
49
|
-
recent = moment().subtract("days", 3)
|
50
|
-
el = addTimeEl type: "weekday", datetime: recent.toISOString()
|
51
|
-
defer ->
|
52
|
-
assert.equal getText(el), recent.format("dddd")
|
53
|
-
done()
|
54
|
-
|
55
|
-
testAsync "before this week", (done) ->
|
56
|
-
before = moment().subtract("days", 8)
|
57
|
-
el = addTimeEl type: "weekday", datetime: before.toISOString()
|
58
|
-
defer ->
|
59
|
-
assert.equal getText(el), ""
|
60
|
-
done()
|
61
|
-
|
62
|
-
testGroup "relative weekday or date", ->
|
63
|
-
testAsync "today", (done) ->
|
64
|
-
now = moment()
|
65
|
-
el = addTimeEl type: "weekday-or-date", datetime: now.toISOString()
|
66
|
-
defer ->
|
67
|
-
assert.equal getText(el), "today"
|
68
|
-
done()
|
69
|
-
|
70
|
-
testAsync "yesterday", (done) ->
|
71
|
-
yesterday = moment().subtract("days", 1)
|
72
|
-
el = addTimeEl type: "weekday-or-date", datetime: yesterday.toISOString()
|
73
|
-
defer ->
|
74
|
-
assert.equal getText(el), "yesterday"
|
75
|
-
done()
|
76
|
-
|
77
|
-
testAsync "this week", (done) ->
|
78
|
-
recent = moment().subtract("days", 3)
|
79
|
-
el = addTimeEl type: "weekday-or-date", datetime: recent.toISOString()
|
80
|
-
defer ->
|
81
|
-
assert.equal getText(el), recent.format("dddd")
|
82
|
-
done()
|
83
|
-
|
84
|
-
testAsync "before this week", (done) ->
|
85
|
-
before = moment().subtract("days", 8)
|
86
|
-
el = addTimeEl type: "weekday-or-date", datetime: before.toISOString()
|
87
|
-
defer ->
|
88
|
-
assert.equal getText(el), before.format("MMM D")
|
89
|
-
done()
|
@@ -1,54 +0,0 @@
|
|
1
|
-
{addTimeEl, assert, defer, getText, setText, test, testAsync, testGroup, triggerEvent} = LocalTime.TestHelpers
|
2
|
-
|
3
|
-
momentMap =
|
4
|
-
"%a": "ddd"
|
5
|
-
"%A": "dddd"
|
6
|
-
"%b": "MMM"
|
7
|
-
"%B": "MMMM"
|
8
|
-
"%c": "toString()"
|
9
|
-
"%d": "DD"
|
10
|
-
"%-d": "D"
|
11
|
-
"%e": "D"
|
12
|
-
"%H": "HH"
|
13
|
-
"%-H": "H"
|
14
|
-
"%I": "hh"
|
15
|
-
"%-I": "h"
|
16
|
-
"%l": "h"
|
17
|
-
"%m": "MM"
|
18
|
-
"%-m": "M"
|
19
|
-
"%M": "mm"
|
20
|
-
"%-M": "m"
|
21
|
-
"%p": "A"
|
22
|
-
"%P": "a"
|
23
|
-
"%S": "ss"
|
24
|
-
"%-S": "s"
|
25
|
-
"%w": "e"
|
26
|
-
"%y": "YY"
|
27
|
-
"%Y": "YYYY"
|
28
|
-
|
29
|
-
testGroup "strftime", ->
|
30
|
-
for day in [0..30] by 6
|
31
|
-
do (day) ->
|
32
|
-
for hour in [0..24] by 6
|
33
|
-
do (hour) ->
|
34
|
-
|
35
|
-
for format, momentFormat of momentMap
|
36
|
-
do (format, momentFormat) ->
|
37
|
-
test "#{format} (+#{day} days, #{hour} hours)", ->
|
38
|
-
now = moment().add("days", day).add("hours", hour)
|
39
|
-
el = addTimeEl {format, datetime: now.toISOString()}
|
40
|
-
LocalTime.process(el)
|
41
|
-
|
42
|
-
assert.equal getText(el),
|
43
|
-
if func = momentFormat.match(/(\w+)\(\)/)?[1]
|
44
|
-
now.toDate()[func]()
|
45
|
-
else
|
46
|
-
now.format momentFormat
|
47
|
-
|
48
|
-
test "%Z Timezone (+#{day} days, #{hour} hours)", ->
|
49
|
-
now = moment().add("days", day).add("hours", hour)
|
50
|
-
el = addTimeEl format: "%Z", datetime: now.toISOString()
|
51
|
-
LocalTime.process(el)
|
52
|
-
|
53
|
-
text = getText el
|
54
|
-
assert.ok /^(\w{3,4}|UTC[\+\-]\d+)$/.test(text), "'#{text}' doesn't look like a timezone. System date: '#{new Date}'"
|
@@ -1,43 +0,0 @@
|
|
1
|
-
#= require moment
|
2
|
-
#= require sinon-timers
|
3
|
-
|
4
|
-
#= require_self
|
5
|
-
#= require_directory .
|
6
|
-
|
7
|
-
LocalTime.TestHelpers =
|
8
|
-
assert: QUnit.assert
|
9
|
-
testGroup: QUnit.module
|
10
|
-
test: QUnit.test
|
11
|
-
|
12
|
-
testAsync: (name, callback) ->
|
13
|
-
QUnit.test name, (assert) ->
|
14
|
-
done = assert.async()
|
15
|
-
callback(done)
|
16
|
-
|
17
|
-
addTimeEl: ({format, type, datetime} = {}) ->
|
18
|
-
format ?= "%Y"
|
19
|
-
type ?= "time"
|
20
|
-
datetime ?= "2013-11-12T12:13:00Z"
|
21
|
-
|
22
|
-
el = document.createElement "time"
|
23
|
-
el.setAttribute "data-local", type
|
24
|
-
el.setAttribute "data-format", format
|
25
|
-
el.setAttribute "datetime", datetime
|
26
|
-
document.body.appendChild el
|
27
|
-
el
|
28
|
-
|
29
|
-
setText: (el, text) ->
|
30
|
-
el.textContent = text
|
31
|
-
|
32
|
-
getText: (el) ->
|
33
|
-
# innerHTML works in all browsers so using it ensures we're
|
34
|
-
# reading the text content, not a potentially arbitrary property.
|
35
|
-
el.innerHTML
|
36
|
-
|
37
|
-
triggerEvent: (name, el = document) ->
|
38
|
-
event = document.createEvent "Events"
|
39
|
-
event.initEvent name, true, true
|
40
|
-
el.dispatchEvent event
|
41
|
-
|
42
|
-
defer: (callback) ->
|
43
|
-
setTimeout(callback, 1)
|
@@ -1,56 +0,0 @@
|
|
1
|
-
{addTimeEl, assert, defer, getText, setText, test, testAsync, testGroup, triggerEvent} = LocalTime.TestHelpers
|
2
|
-
|
3
|
-
testGroup "time ago", ->
|
4
|
-
test "a second ago", ->
|
5
|
-
assertTimeAgo "a second ago", "seconds", 9
|
6
|
-
|
7
|
-
test "seconds ago", ->
|
8
|
-
assertTimeAgo "44 seconds ago", "seconds", 44
|
9
|
-
|
10
|
-
test "a minute ago", ->
|
11
|
-
assertTimeAgo "a minute ago", "seconds", 89
|
12
|
-
|
13
|
-
test "minutes ago", ->
|
14
|
-
assertTimeAgo "44 minutes ago", "minutes", 44
|
15
|
-
|
16
|
-
test "an hour ago", ->
|
17
|
-
assertTimeAgo "an hour ago", "minutes", 89
|
18
|
-
|
19
|
-
test "hours ago", ->
|
20
|
-
assertTimeAgo "23 hours ago", "hours", 23
|
21
|
-
|
22
|
-
test "yesterday", ->
|
23
|
-
time = moment().subtract("days", 1).format "h:mma"
|
24
|
-
assertTimeAgo "yesterday at #{time}", "days", 1
|
25
|
-
|
26
|
-
test "tomorrow", ->
|
27
|
-
time = moment().add("days", 1).format "h:mma"
|
28
|
-
assertTimeAgo "tomorrow at #{time}", "days", -1
|
29
|
-
|
30
|
-
test "last week", ->
|
31
|
-
ago = moment().subtract "days", 5
|
32
|
-
day = ago.format "dddd"
|
33
|
-
time = ago.format "h:mma"
|
34
|
-
|
35
|
-
assertTimeAgo "#{day} at #{time}", "days", 5
|
36
|
-
|
37
|
-
test "this year", ->
|
38
|
-
clock = sinon.useFakeTimers(new Date(2013,11,11,11,11).getTime(), "Date")
|
39
|
-
date = moment().subtract("days", 7).format "MMM D"
|
40
|
-
assertTimeAgo "on #{date}", "days", 7
|
41
|
-
clock.restore()
|
42
|
-
|
43
|
-
test "last year", ->
|
44
|
-
date = moment().subtract("days", 366).format "MMM D, YYYY"
|
45
|
-
assertTimeAgo "on #{date}", "days", 366
|
46
|
-
|
47
|
-
test "next year", ->
|
48
|
-
date = moment().add("days", 366).format "MMM D, YYYY"
|
49
|
-
assertTimeAgo "on #{date}", "days", -366
|
50
|
-
|
51
|
-
assertTimeAgo = (string, unit, amount) ->
|
52
|
-
el = document.getElementById "ago"
|
53
|
-
el.setAttribute "data-local", "time-ago"
|
54
|
-
el.setAttribute "datetime", moment().subtract(unit, amount).utc().toISOString()
|
55
|
-
LocalTime.run()
|
56
|
-
assert.equal getText(el), string
|