local_time 3.0.2 → 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 +7 -1
- data/app/assets/javascripts/local-time.es2017-esm.js +1 -1
- data/app/assets/javascripts/local-time.es2017-umd.js +1 -1
- data/lib/local_time/version.rb +1 -1
- data/test/helpers/local_time_helper_test.rb +1 -7
- data/test/javascripts/builds/index.js +23787 -21189
- data/test/javascripts/src/format24_test.js +109 -0
- data/test/javascripts/src/i18n_test.js +55 -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 +5650 -5647
- data/test/javascripts/vendor/sinon.js +18218 -15475
- metadata +23 -23
- data/test/javascripts/src/format24_test.coffee +0 -94
- data/test/javascripts/src/i18n_test.coffee +0 -49
- data/test/javascripts/src/local_time_test.coffee +0 -43
- data/test/javascripts/src/relative_date_test.coffee +0 -91
- data/test/javascripts/src/strftime_test.coffee +0 -127
- data/test/javascripts/src/test_helpers.coffee +0 -46
- data/test/javascripts/src/time_ago_test.coffee +0 -58
- /data/test/javascripts/src/{index.coffee → index.js} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 799fafd7b55d67b64c0038f8d9d88a6e521a858916aff976b3bbc6ddd3a588f7
|
4
|
+
data.tar.gz: 48000c9b35e80ae555ae629d75734896e9b78deeeb7443ca828f38903fd6c314
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6e47fd634ccdfebd71260e05f49d87d6dc80b1aeef0353988d5f8d1f2bc92188073cef9e0a910d0d97fee6d2bc037507669c95b35769a978c8e7b2907ac960f
|
7
|
+
data.tar.gz: 3473c5d757047367067087363875824a472adcacd4221a64965c3b1d4d58da3102b569c326c07f55fbe3152bd2c9d9aec80124a0e1093c1ef16f63b8f5e526aa
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -13,6 +13,9 @@ Local Time makes it easy to display times and dates to users in their local time
|
|
13
13
|
```js
|
14
14
|
import LocalTime from "local-time"
|
15
15
|
LocalTime.start()
|
16
|
+
document.addEventListener("turbo:morph", () => {
|
17
|
+
LocalTime.run()
|
18
|
+
})
|
16
19
|
```
|
17
20
|
|
18
21
|
### Webpacker
|
@@ -131,7 +134,7 @@ Preset time and date formats that vary with age. The available types are `date`,
|
|
131
134
|
|
132
135
|
**Internationalization (I18n)**
|
133
136
|
|
134
|
-
Local Time includes a [set of default `en` translations](lib/assets/javascripts/src/local-time/config/i18n.
|
137
|
+
Local Time includes a [set of default `en` translations](lib/assets/javascripts/src/local-time/config/i18n.js) which can be updated directly. Or, you can provide an entirely new set in a different locale:
|
135
138
|
|
136
139
|
```js
|
137
140
|
LocalTime.config.i18n["es"] = {
|
@@ -151,6 +154,9 @@ LocalTime.config.i18n["es"] = {
|
|
151
154
|
LocalTime.config.locale = "es"
|
152
155
|
```
|
153
156
|
|
157
|
+
> [!NOTE]
|
158
|
+
> The "default" keys in the i18n configuration object are used for translations in LocalTime's `RelativeTime` module. They are not used to determine which format is rendered when none is provided. See https://github.com/basecamp/local_time/issues/128 for details.
|
159
|
+
|
154
160
|
**24-hour time formatting**
|
155
161
|
Local Time supports 24-hour time formats out of the box.
|
156
162
|
|
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
const t={config:{},run(){this.getController().processElements()},process(...t){for(const e of t)this.getController().processElement(e);return t.length},getController(){return this.controller?this.controller:this.controller=new t.Controller}};t.config.useFormat24=!1,t.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",default_24h:"%H:%M"}},datetime:{at:"{date} at {time}",formats:{default:"%B %e, %Y at %l:%M%P %Z",default_24h:"%B %e, %Y at %H:%M %Z"}}}},t.config.locale="en",t.config.defaultLocale="en",t.config.timerInterval=6e4;const e=!isNaN(Date.parse("2011-01-01T12:00:00-05:00"));t.parseDate=t=>(t=t.toString(),e||(t=function(t){const e=t.match(r);if(e){let t;const[r,a,s,n,i,o,c,u]=e;return"Z"!==u&&(t=u.replace(":","")),`${a}/${s}/${n} ${i}:${o}:${c} GMT${[t]}`}}(t)),new Date(Date.parse(t)));const r=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(Z|[-+]?[\d:]+)$/;t.elementMatchesSelector=(()=>{const t=document.documentElement,e=t.matches||t.matchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;return(t,r)=>{if(t?.nodeType===Node.ELEMENT_NODE)return e.call(t,r)}})();const{config:a}=t,{i18n:s}=a;t.getI18nValue=(e="",r={locale:a.locale})=>{const{locale:n}=r,i=function(t,e){let r=t;for(var a of Array.from(e.split("."))){if(!r[a])return null;r=r[a]}return r}(s[n],e);return i||(n!==a.defaultLocale?t.getI18nValue(e,{locale:a.defaultLocale}):void 0)},t.translate=(e,r={},a)=>{let s=t.getI18nValue(e,a);for(const t in r){const e=r[t];s=s.replace(`{${t}}`,e)}return s};const{getI18nValue:n,translate:i}=t,o="function"==typeof Intl?.DateTimeFormat,c={"Central European Standard Time":"CET","Central European Summer Time":"CEST","China Standard Time":"CST","Israel Daylight Time":"IDT","Israel Standard Time":"IST","Moscow Standard Time":"MSK","Peru Standard Time":"PET","Philippine Standard Time":"PHT","Singapore Standard Time":"SGT","Western Indonesia Time":"WIB"};t.knownEdgeCaseTimeZones=c,t.strftime=(()=>{const t=(a,s)=>{const u=a.getDay(),l=a.getDate(),d=a.getMonth(),m=a.getFullYear(),h=a.getHours(),f=a.getMinutes(),g=a.getSeconds();return s.replace(/%(-?)([%aAbBcdeHIlmMpPSwyYZ])/g,((s,p,y)=>{switch(y){case"%":return"%";case"a":return n("date.abbrDayNames")[u];case"A":return n("date.dayNames")[u];case"b":return n("date.abbrMonthNames")[d];case"B":return n("date.monthNames")[d];case"c":return a.toString();case"d":return e(l,p);case"e":return l;case"H":return e(h,p);case"I":return e(t(a,"%l"),p);case"l":return 0===h||12===h?12:(h+12)%12;case"m":return e(d+1,p);case"M":return e(f,p);case"p":return i("time."+(h>11?"pm":"am")).toUpperCase();case"P":return i("time."+(h>11?"pm":"am"));case"S":return e(g,p);case"w":return u;case"y":return e(m%100,p);case"Y":return m;case"Z":return function(t){let e,a,s;return(a=function(t){return Object.keys(c).find((e=>o?new Date(t).toLocaleString("en-US",{timeZoneName:"long"}).includes(e):t.toString().includes(e)))}(t))?c[a]:(s=r(t,{allowGMT:!1}))||(s=function(t){const e=t.toString();let r;if(null!=(r=e.match(/\(([\w\s]+)\)$/))){const t=r[1];return/\s/.test(t)?t.match(/\b(\w)/g).join(""):t}if(null!=(r=e.match(/(\w{3,4})\s\d{4}$/)))return r[1];if(null!=(r=e.match(/(UTC[\+\-]\d+)/)))return r[1]}(t))?s:(e=r(t,{allowGMT:!0}))?e:""}(a)}}))};function e(t,e){return"-"===e?t:`0${t}`.slice(-2)}function r(t,{allowGMT:e}){if(o){const r=new Date(t).toLocaleString("en-US",{timeZoneName:"short"}).split(" ").pop();if(e||!r.includes("GMT"))return r}}return t})(),t.CalendarDate=class{static fromDate(t){return new this(t.getFullYear(),t.getMonth()+1,t.getDate())}static today(){return this.fromDate(new Date)}constructor(t,e,r){this.date=new Date(Date.UTC(t,e-1)),this.date.setUTCDate(r),this.year=this.date.getUTCFullYear(),this.month=this.date.getUTCMonth()+1,this.day=this.date.getUTCDate(),this.value=this.date.getTime()}equals(t){return t?.value===this.value}is(t){return this.equals(t)}isToday(){return this.is(this.constructor.today())}occursOnSameYearAs(t){return this.year===t?.year}occursThisYear(){return this.occursOnSameYearAs(this.constructor.today())}daysSince(t){if(t)return(this.date-t.date)/864e5}daysPassed(){return this.constructor.today().daysSince(this)}};const{strftime:u,translate:l,getI18nValue:d,config:m}=t;t.RelativeTime=class{constructor(e){this.date=e,this.calendarDate=t.CalendarDate.fromDate(this.date)}toString(){let t,e;return(e=this.toTimeElapsedString())?l("time.elapsed",{time:e}):(t=this.toWeekdayString())?(e=this.toTimeString(),l("datetime.at",{date:t,time:e})):l("date.on",{date:this.toDateString()})}toTimeOrDateString(){return this.calendarDate.isToday()?this.toTimeString():this.toDateString()}toTimeElapsedString(){let t;const e=(new Date).getTime()-this.date.getTime(),r=Math.round(e/1e3),a=Math.round(r/60),s=Math.round(a/60);return e<0?null:r<10?(t=l("time.second"),l("time.singular",{time:t})):r<45?`${r} ${l("time.seconds")}`:r<90?(t=l("time.minute"),l("time.singular",{time:t})):a<45?`${a} ${l("time.minutes")}`:a<90?(t=l("time.hour"),l("time.singularAn",{time:t})):s<24?`${s} ${l("time.hours")}`:""}toWeekdayString(){switch(this.calendarDate.daysPassed()){case 0:return l("date.today");case 1:return l("date.yesterday");case-1:return l("date.tomorrow");case 2:case 3:case 4:case 5:case 6:return u(this.date,"%A");default:return""}}toDateString(){const t=this.calendarDate.occursThisYear()?d("date.formats.thisYear"):d("date.formats.default");return u(this.date,t)}toTimeString(){const t=m.useFormat24?"default_24h":"default";return u(this.date,d(`time.formats.${t}`))}};const{elementMatchesSelector:h}=t;t.PageObserver=class{constructor(t,e){this.selector=t,this.callback=e,this.processMutations=this.processMutations.bind(this),this.processInsertion=this.processInsertion.bind(this)}start(){this.started||(this.observeWithMutationObserver()||this.observeWithMutationEvent(),this.started=!0)}observeWithMutationObserver(){if("undefined"!=typeof MutationObserver&&null!==MutationObserver){return new MutationObserver(this.processMutations).observe(document.documentElement,{childList:!0,subtree:!0}),!0}return!1}observeWithMutationEvent(){return addEventListener("DOMNodeInserted",this.processInsertion,!1),!0}findSignificantElements(t){const e=[];return t?.nodeType===Node.ELEMENT_NODE&&(h(t,this.selector)&&e.push(t),e.push(...Array.from(t.querySelectorAll(this.selector)||[]))),e}processMutations(t){const e=[];for(const r of t)if("childList"===r.type)for(const t of r.addedNodes)e.push(...this.findSignificantElements(t)||[]);this.notify(e)}processInsertion(t){const e=this.findSignificantElements(t.target);this.notify(e)}notify(t){t?.length>0&&"function"==typeof this.callback&&this.callback(t)}};const{parseDate:f,strftime:g,getI18nValue:p,config:y}=t,S="time[data-local]:not([data-localized])",T=t=>t.setAttribute("data-localized",""),b=e=>new t.RelativeTime(e);t.Controller=class{constructor(){this.processElements=this.processElements.bind(this),this.pageObserver=new t.PageObserver(S,this.processElements)}start(){this.started||(this.processElements(),this.startTimer(),this.pageObserver.start(),this.started=!0)}startTimer(){let t;(t=y.timerInterval)&&(this.timer||(this.timer=setInterval(this.processElements,t)))}processElements(t){t||(t=document.querySelectorAll(S));for(const e of Array.from(t))this.processElement(e);return t.length}processElement(t){const e=t.getAttribute("datetime"),r=t.getAttribute("data-local"),a=y.useFormat24&&t.getAttribute("data-format24")||t.getAttribute("data-format"),s=f(e);if(!isNaN(s)){if(!t.hasAttribute("title")){const e=y.useFormat24?"default_24h":"default",r=g(s,p(`datetime.formats.${e}`));t.setAttribute("title",r)}(t=>{t.setAttribute("data-processed-at",(new Date).toISOString())})(t),t.textContent=(()=>{switch(r){case"time":return T(t),g(s,a);case"date":return T(t),b(s).toDateString();case"time-ago":return b(s).toString();case"time-or-date":return b(s).toTimeOrDateString();case"weekday":return b(s).toWeekdayString();case"weekday-or-date":return b(s).toWeekdayString()||b(s).toDateString()}})()}}};let M=!1;function D(){t.getController().start()}t.start=()=>{var e;M?t.run():(M=!0,"undefined"!=typeof MutationObserver&&null!==MutationObserver||(document.attachEvent?"complete"===document.readyState:"loading"!==document.readyState)?D():(e=D,"function"==typeof requestAnimationFrame?requestAnimationFrame(e):setTimeout(e,17)))},t.processing=()=>t.getController().started,window.LocalTime===t&&t.start();export{t as default};
|
@@ -1 +1 @@
|
|
1
|
-
!function(e
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).LocalTime=e()}(this,(function(){"use strict";const t={config:{},run(){this.getController().processElements()},process(...t){for(const e of t)this.getController().processElement(e);return t.length},getController(){return this.controller?this.controller:this.controller=new t.Controller}};t.config.useFormat24=!1,t.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",default_24h:"%H:%M"}},datetime:{at:"{date} at {time}",formats:{default:"%B %e, %Y at %l:%M%P %Z",default_24h:"%B %e, %Y at %H:%M %Z"}}}},t.config.locale="en",t.config.defaultLocale="en",t.config.timerInterval=6e4;const e=!isNaN(Date.parse("2011-01-01T12:00:00-05:00"));t.parseDate=t=>(t=t.toString(),e||(t=function(t){const e=t.match(r);if(e){let t;const[r,a,s,n,i,o,c,u]=e;return"Z"!==u&&(t=u.replace(":","")),`${a}/${s}/${n} ${i}:${o}:${c} GMT${[t]}`}}(t)),new Date(Date.parse(t)));const r=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(Z|[-+]?[\d:]+)$/;t.elementMatchesSelector=(()=>{const t=document.documentElement,e=t.matches||t.matchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector||t.msMatchesSelector;return(t,r)=>{if(t?.nodeType===Node.ELEMENT_NODE)return e.call(t,r)}})();const{config:a}=t,{i18n:s}=a;t.getI18nValue=(e="",r={locale:a.locale})=>{const{locale:n}=r,i=function(t,e){let r=t;for(var a of Array.from(e.split("."))){if(!r[a])return null;r=r[a]}return r}(s[n],e);return i||(n!==a.defaultLocale?t.getI18nValue(e,{locale:a.defaultLocale}):void 0)},t.translate=(e,r={},a)=>{let s=t.getI18nValue(e,a);for(const t in r){const e=r[t];s=s.replace(`{${t}}`,e)}return s};const{getI18nValue:n,translate:i}=t,o="function"==typeof Intl?.DateTimeFormat,c={"Central European Standard Time":"CET","Central European Summer Time":"CEST","China Standard Time":"CST","Israel Daylight Time":"IDT","Israel Standard Time":"IST","Moscow Standard Time":"MSK","Peru Standard Time":"PET","Philippine Standard Time":"PHT","Singapore Standard Time":"SGT","Western Indonesia Time":"WIB"};t.knownEdgeCaseTimeZones=c,t.strftime=(()=>{const t=(a,s)=>{const u=a.getDay(),l=a.getDate(),d=a.getMonth(),m=a.getFullYear(),h=a.getHours(),f=a.getMinutes(),g=a.getSeconds();return s.replace(/%(-?)([%aAbBcdeHIlmMpPSwyYZ])/g,((s,p,y)=>{switch(y){case"%":return"%";case"a":return n("date.abbrDayNames")[u];case"A":return n("date.dayNames")[u];case"b":return n("date.abbrMonthNames")[d];case"B":return n("date.monthNames")[d];case"c":return a.toString();case"d":return e(l,p);case"e":return l;case"H":return e(h,p);case"I":return e(t(a,"%l"),p);case"l":return 0===h||12===h?12:(h+12)%12;case"m":return e(d+1,p);case"M":return e(f,p);case"p":return i("time."+(h>11?"pm":"am")).toUpperCase();case"P":return i("time."+(h>11?"pm":"am"));case"S":return e(g,p);case"w":return u;case"y":return e(m%100,p);case"Y":return m;case"Z":return function(t){let e,a,s;return(a=function(t){return Object.keys(c).find((e=>o?new Date(t).toLocaleString("en-US",{timeZoneName:"long"}).includes(e):t.toString().includes(e)))}(t))?c[a]:(s=r(t,{allowGMT:!1}))||(s=function(t){const e=t.toString();let r;if(null!=(r=e.match(/\(([\w\s]+)\)$/))){const t=r[1];return/\s/.test(t)?t.match(/\b(\w)/g).join(""):t}if(null!=(r=e.match(/(\w{3,4})\s\d{4}$/)))return r[1];if(null!=(r=e.match(/(UTC[\+\-]\d+)/)))return r[1]}(t))?s:(e=r(t,{allowGMT:!0}))?e:""}(a)}}))};function e(t,e){return"-"===e?t:`0${t}`.slice(-2)}function r(t,{allowGMT:e}){if(o){const r=new Date(t).toLocaleString("en-US",{timeZoneName:"short"}).split(" ").pop();if(e||!r.includes("GMT"))return r}}return t})(),t.CalendarDate=class{static fromDate(t){return new this(t.getFullYear(),t.getMonth()+1,t.getDate())}static today(){return this.fromDate(new Date)}constructor(t,e,r){this.date=new Date(Date.UTC(t,e-1)),this.date.setUTCDate(r),this.year=this.date.getUTCFullYear(),this.month=this.date.getUTCMonth()+1,this.day=this.date.getUTCDate(),this.value=this.date.getTime()}equals(t){return t?.value===this.value}is(t){return this.equals(t)}isToday(){return this.is(this.constructor.today())}occursOnSameYearAs(t){return this.year===t?.year}occursThisYear(){return this.occursOnSameYearAs(this.constructor.today())}daysSince(t){if(t)return(this.date-t.date)/864e5}daysPassed(){return this.constructor.today().daysSince(this)}};const{strftime:u,translate:l,getI18nValue:d,config:m}=t;t.RelativeTime=class{constructor(e){this.date=e,this.calendarDate=t.CalendarDate.fromDate(this.date)}toString(){let t,e;return(e=this.toTimeElapsedString())?l("time.elapsed",{time:e}):(t=this.toWeekdayString())?(e=this.toTimeString(),l("datetime.at",{date:t,time:e})):l("date.on",{date:this.toDateString()})}toTimeOrDateString(){return this.calendarDate.isToday()?this.toTimeString():this.toDateString()}toTimeElapsedString(){let t;const e=(new Date).getTime()-this.date.getTime(),r=Math.round(e/1e3),a=Math.round(r/60),s=Math.round(a/60);return e<0?null:r<10?(t=l("time.second"),l("time.singular",{time:t})):r<45?`${r} ${l("time.seconds")}`:r<90?(t=l("time.minute"),l("time.singular",{time:t})):a<45?`${a} ${l("time.minutes")}`:a<90?(t=l("time.hour"),l("time.singularAn",{time:t})):s<24?`${s} ${l("time.hours")}`:""}toWeekdayString(){switch(this.calendarDate.daysPassed()){case 0:return l("date.today");case 1:return l("date.yesterday");case-1:return l("date.tomorrow");case 2:case 3:case 4:case 5:case 6:return u(this.date,"%A");default:return""}}toDateString(){const t=this.calendarDate.occursThisYear()?d("date.formats.thisYear"):d("date.formats.default");return u(this.date,t)}toTimeString(){const t=m.useFormat24?"default_24h":"default";return u(this.date,d(`time.formats.${t}`))}};const{elementMatchesSelector:h}=t;t.PageObserver=class{constructor(t,e){this.selector=t,this.callback=e,this.processMutations=this.processMutations.bind(this),this.processInsertion=this.processInsertion.bind(this)}start(){this.started||(this.observeWithMutationObserver()||this.observeWithMutationEvent(),this.started=!0)}observeWithMutationObserver(){if("undefined"!=typeof MutationObserver&&null!==MutationObserver){return new MutationObserver(this.processMutations).observe(document.documentElement,{childList:!0,subtree:!0}),!0}return!1}observeWithMutationEvent(){return addEventListener("DOMNodeInserted",this.processInsertion,!1),!0}findSignificantElements(t){const e=[];return t?.nodeType===Node.ELEMENT_NODE&&(h(t,this.selector)&&e.push(t),e.push(...Array.from(t.querySelectorAll(this.selector)||[]))),e}processMutations(t){const e=[];for(const r of t)if("childList"===r.type)for(const t of r.addedNodes)e.push(...this.findSignificantElements(t)||[]);this.notify(e)}processInsertion(t){const e=this.findSignificantElements(t.target);this.notify(e)}notify(t){t?.length>0&&"function"==typeof this.callback&&this.callback(t)}};const{parseDate:f,strftime:g,getI18nValue:p,config:y}=t,S="time[data-local]:not([data-localized])",T=t=>t.setAttribute("data-localized",""),b=e=>new t.RelativeTime(e);t.Controller=class{constructor(){this.processElements=this.processElements.bind(this),this.pageObserver=new t.PageObserver(S,this.processElements)}start(){this.started||(this.processElements(),this.startTimer(),this.pageObserver.start(),this.started=!0)}startTimer(){let t;(t=y.timerInterval)&&(this.timer||(this.timer=setInterval(this.processElements,t)))}processElements(t){t||(t=document.querySelectorAll(S));for(const e of Array.from(t))this.processElement(e);return t.length}processElement(t){const e=t.getAttribute("datetime"),r=t.getAttribute("data-local"),a=y.useFormat24&&t.getAttribute("data-format24")||t.getAttribute("data-format"),s=f(e);if(!isNaN(s)){if(!t.hasAttribute("title")){const e=y.useFormat24?"default_24h":"default",r=g(s,p(`datetime.formats.${e}`));t.setAttribute("title",r)}(t=>{t.setAttribute("data-processed-at",(new Date).toISOString())})(t),t.textContent=(()=>{switch(r){case"time":return T(t),g(s,a);case"date":return T(t),b(s).toDateString();case"time-ago":return b(s).toString();case"time-or-date":return b(s).toTimeOrDateString();case"weekday":return b(s).toWeekdayString();case"weekday-or-date":return b(s).toWeekdayString()||b(s).toDateString()}})()}}};let M=!1;function D(){t.getController().start()}return t.start=()=>{var e;M?t.run():(M=!0,"undefined"!=typeof MutationObserver&&null!==MutationObserver||(document.attachEvent?"complete"===document.readyState:"loading"!==document.readyState)?D():(e=D,"function"==typeof requestAnimationFrame?requestAnimationFrame(e):setTimeout(e,17)))},t.processing=()=>t.getController().started,window.LocalTime===t&&t.start(),t}));
|
data/lib/local_time/version.rb
CHANGED
@@ -7,13 +7,7 @@ require "local_time"
|
|
7
7
|
require_relative "../../app/helpers/local_time_helper"
|
8
8
|
|
9
9
|
require "minitest/autorun"
|
10
|
-
|
11
|
-
# 2.0.0
|
12
|
-
class TestCase < MiniTest::Test; end
|
13
|
-
rescue NameError
|
14
|
-
# 1.9.3
|
15
|
-
class TestCase < MiniTest::Unit::TestCase; end
|
16
|
-
end
|
10
|
+
class TestCase < Minitest::Test; end
|
17
11
|
|
18
12
|
I18n.enforce_available_locales = false
|
19
13
|
|