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.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: local_time
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javan Makhmali
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-01-15 00:00:00.000000000 Z
12
+ date: 2025-03-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -71,14 +71,14 @@ files:
71
71
  - test/javascripts/fixtures/index.html
72
72
  - test/javascripts/fixtures/time_zone_check.html
73
73
  - test/javascripts/server.mjs
74
- - test/javascripts/src/format24_test.coffee
75
- - test/javascripts/src/i18n_test.coffee
76
- - test/javascripts/src/index.coffee
77
- - test/javascripts/src/local_time_test.coffee
78
- - test/javascripts/src/relative_date_test.coffee
79
- - test/javascripts/src/strftime_test.coffee
80
- - test/javascripts/src/test_helpers.coffee
81
- - test/javascripts/src/time_ago_test.coffee
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
82
82
  - test/javascripts/vendor/moment.js
83
83
  - test/javascripts/vendor/sinon.js
84
84
  homepage: https://github.com/basecamp/local_time
@@ -100,23 +100,23 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  - !ruby/object:Gem::Version
101
101
  version: '0'
102
102
  requirements: []
103
- rubygems_version: 3.4.21
103
+ rubygems_version: 3.1.6
104
104
  signing_key:
105
105
  specification_version: 4
106
106
  summary: Rails engine for cache-friendly, client-side local time
107
107
  test_files:
108
- - test/javascripts/builds/index.js
109
108
  - test/javascripts/server.mjs
110
- - test/javascripts/fixtures/index.html
111
- - test/javascripts/fixtures/time_zone_check.html
112
- - test/javascripts/vendor/moment.js
109
+ - test/javascripts/builds/index.js
113
110
  - test/javascripts/vendor/sinon.js
114
- - test/javascripts/src/strftime_test.coffee
115
- - test/javascripts/src/index.coffee
116
- - test/javascripts/src/i18n_test.coffee
117
- - test/javascripts/src/local_time_test.coffee
118
- - test/javascripts/src/time_ago_test.coffee
119
- - test/javascripts/src/format24_test.coffee
120
- - test/javascripts/src/relative_date_test.coffee
121
- - test/javascripts/src/test_helpers.coffee
111
+ - test/javascripts/vendor/moment.js
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
122
  - test/helpers/local_time_helper_test.rb
@@ -1,94 +0,0 @@
1
- import LocalTime from "local_time"
2
-
3
- {addTimeEl, assert, defer, getText, testAsync, testGroup, getTitle} = LocalTime.TestHelpers
4
- {config} = LocalTime
5
-
6
- testGroup "format24 (24h time)", ->
7
- testAsync "default behavior", (done) ->
8
- now = moment()
9
-
10
- el = addTimeEl format: "%-l:%M%P", format24: "%H:%M", datetime: now.toISOString()
11
- defer ->
12
- assert.equal getText(el), now.format("h:mma")
13
- done()
14
-
15
- testAsync "turned off", (done) ->
16
- now = moment()
17
- originalFormat24 = config.useFormat24
18
- config.useFormat24 = false
19
-
20
- el = addTimeEl format: "%-l:%M%P", format24: "%H:%M", datetime: now.toISOString()
21
- defer ->
22
- assert.equal getText(el), now.format("h:mma")
23
- config.useFormat24 = originalFormat24
24
- done()
25
-
26
- testAsync "turned on", (done) ->
27
- now = moment()
28
- originalFormat24 = config.useFormat24
29
- config.useFormat24 = true
30
-
31
- el = addTimeEl format: "%-l:%M%P", format24: "%H:%M", datetime: now.toISOString()
32
- defer ->
33
- assert.equal getText(el), now.format("HH:mm")
34
- config.useFormat24 = originalFormat24
35
- done()
36
-
37
- testAsync "fallback for missing data-format24 values", (done) ->
38
- now = moment()
39
- originalFormat24 = config.useFormat24
40
- config.useFormat24 = true
41
-
42
- el = addTimeEl format: "%-l:%M%P", datetime: now.toISOString()
43
- defer ->
44
- assert.equal getText(el), now.format("h:mma")
45
- config.useFormat24 = originalFormat24
46
- done()
47
-
48
- testAsync "turned off for relative time elements", (done) ->
49
- ago = moment().subtract("days", 5)
50
- originalFormat24 = config.useFormat24
51
- config.useFormat24 = false
52
-
53
- el = addTimeEl type: "time-ago", datetime: ago.toISOString()
54
- defer ->
55
- assert.equal getText(el), "#{ago.format("dddd")} at #{ago.format("h:mma")}"
56
- config.useFormat24 = originalFormat24
57
- done()
58
-
59
- testAsync "turned on for relative time elements", (done) ->
60
- ago = moment().subtract("days", 5)
61
- originalFormat24 = config.useFormat24
62
- config.useFormat24 = true
63
-
64
- el = addTimeEl type: "time-ago", datetime: ago.toISOString()
65
- defer ->
66
- assert.equal getText(el), "#{ago.format("dddd")} at #{ago.format("HH:mm")}"
67
- config.useFormat24 = originalFormat24
68
- done()
69
-
70
- testAsync "element title when turned off", (done) ->
71
- ago = moment().subtract("days", 5)
72
- originalFormat24 = config.useFormat24
73
- config.useFormat24 = false
74
-
75
- el = addTimeEl type: "time-ago", datetime: ago.toISOString()
76
- defer ->
77
- regex = new RegExp(ago.format('MMMM D, YYYY [at] h:mma') + " (\\w{3,4}|UTC[+-]d+)")
78
- assert.ok regex.test(getTitle(el)), "'#{getTitle(el)}' doesn't look correct, it should match regex #{regex}"
79
- config.useFormat24 = originalFormat24
80
- done()
81
-
82
-
83
- testAsync "element title when turned on", (done) ->
84
- ago = moment().subtract("days", 5)
85
- originalFormat24 = config.useFormat24
86
- config.useFormat24 = true
87
-
88
- el = addTimeEl type: "time-ago", datetime: ago.toISOString()
89
- defer ->
90
- regex = new RegExp(ago.format('MMMM D, YYYY [at] HH:mm') + " (\\w{3,4}|UTC[+-]d+)")
91
- assert.ok regex.test(getTitle(el)), "'#{getTitle(el)}' doesn't look correct, it should match regex #{regex}"
92
- config.useFormat24 = originalFormat24
93
- done()
94
-
@@ -1,49 +0,0 @@
1
- import LocalTime from "local_time"
2
-
3
- {addTimeEl, assert, defer, getText, setText, test, testAsync, testGroup, triggerEvent} = LocalTime.TestHelpers
4
- {config} = LocalTime
5
- {i18n} = config
6
-
7
- testGroup "i18n", ->
8
- testAsync "updating a value", (done) ->
9
- now = moment()
10
- values = i18n[config.defaultLocale].date
11
-
12
- originalValue = values.today
13
- values.today = "2day"
14
-
15
- el = addTimeEl type: "weekday", datetime: now.toISOString()
16
- defer ->
17
- assert.equal getText(el), "2day"
18
- assert.equal getText(el), "2day"
19
- values.today = originalValue
20
- done()
21
-
22
- testAsync "adding a new locale", (done) ->
23
- now = moment()
24
-
25
- originalLocale = config.locale
26
- config.locale = "es"
27
- i18n.es = date: today: "hoy"
28
-
29
- el = addTimeEl type: "weekday", datetime: now.toISOString()
30
- defer ->
31
- assert.equal getText(el), "hoy"
32
- config.locale = originalLocale
33
- done()
34
-
35
- testAsync "falling back to the default locale", (done) ->
36
- now = moment()
37
- yesterday = moment().subtract("days", 1)
38
-
39
- originalLocale = config.locale
40
- config.locale = "es"
41
- i18n.es = date: yesterday: "ayer"
42
-
43
- elWithTranslation = addTimeEl type: "weekday", datetime: yesterday.toISOString()
44
- elWithoutTranslation = addTimeEl type: "weekday", datetime: now.toISOString()
45
- defer ->
46
- assert.equal getText(elWithTranslation), "ayer"
47
- assert.equal getText(elWithoutTranslation), "today"
48
- config.locale = originalLocale
49
- done()
@@ -1,43 +0,0 @@
1
- import LocalTime from "local_time"
2
-
3
- {addTimeEl, assert, defer, getText, setText, test, testAsync, testGroup, triggerEvent} = LocalTime.TestHelpers
4
-
5
- testGroup "localized", ->
6
- for id in ["one", "two", "past", "future"]
7
- test id, ->
8
- assertLocalized id
9
-
10
- test "date", ->
11
- assertLocalized "date", "date"
12
-
13
- test "unparseable time", ->
14
- el = addTimeEl format: "%Y", datetime: ":("
15
- setText el, "2013"
16
- assert.equal getText(el), "2013"
17
-
18
- test "processed timestamp", ->
19
- el = addTimeEl type: "time-or-date", datetime: moment().toISOString()
20
- assert.notOk el.getAttribute("data-processed-at")
21
- LocalTime.run()
22
- assert.ok el.getAttribute("data-processed-at")
23
-
24
- assertLocalized = (id, type = "time") ->
25
- switch type
26
- when "time"
27
- momentFormat = "MMMM D, YYYY h:mma"
28
- compare = "toString"
29
- when "date"
30
- momentFormat = "MMMM D, YYYY"
31
- compare = "dayOfYear"
32
-
33
- el = document.getElementById id
34
-
35
- assert.ok datetime = el.getAttribute "datetime"
36
- assert.ok local = getText el
37
-
38
- datetimeParsed = moment datetime
39
- localParsed = moment local, momentFormat
40
-
41
- assert.ok datetimeParsed.isValid()
42
- assert.ok localParsed.isValid()
43
- assert.equal datetimeParsed[compare](), localParsed[compare]()
@@ -1,91 +0,0 @@
1
- import LocalTime from "local_time"
2
-
3
- {addTimeEl, assert, defer, getText, setText, test, testAsync, testGroup, triggerEvent} = LocalTime.TestHelpers
4
-
5
- testGroup "relative date", ->
6
- testAsync "this year", (done) ->
7
- now = moment()
8
- el = addTimeEl type: "date", datetime: now.toISOString()
9
- defer ->
10
- assert.equal getText(el), now.format("MMM D")
11
- done()
12
-
13
- testAsync "last year", (done) ->
14
- before = moment().subtract("years", 1).subtract("days", 1)
15
- el = addTimeEl type: "date", datetime: before.toISOString()
16
- defer ->
17
- assert.equal getText(el), before.format("MMM D, YYYY")
18
- done()
19
-
20
- testGroup "relative time or date", ->
21
- testAsync "today", (done) ->
22
- now = moment()
23
- el = addTimeEl type: "time-or-date", datetime: now.toISOString()
24
- defer ->
25
- assert.equal getText(el), now.format("h:mma")
26
- done()
27
-
28
- testAsync "before today", (done) ->
29
- before = moment().subtract("days", 1)
30
- el = addTimeEl type: "time-or-date", datetime: before.toISOString()
31
- defer ->
32
- assert.equal getText(el), before.format("MMM D")
33
- done()
34
-
35
- testGroup "relative weekday", ->
36
- testAsync "today", (done) ->
37
- now = moment()
38
- el = addTimeEl type: "weekday", datetime: now.toISOString()
39
- defer ->
40
- assert.equal getText(el), "today"
41
- done()
42
-
43
- testAsync "yesterday", (done) ->
44
- yesterday = moment().subtract("days", 1)
45
- el = addTimeEl type: "weekday", datetime: yesterday.toISOString()
46
- defer ->
47
- assert.equal getText(el), "yesterday"
48
- done()
49
-
50
- testAsync "this week", (done) ->
51
- recent = moment().subtract("days", 3)
52
- el = addTimeEl type: "weekday", datetime: recent.toISOString()
53
- defer ->
54
- assert.equal getText(el), recent.format("dddd")
55
- done()
56
-
57
- testAsync "before this week", (done) ->
58
- before = moment().subtract("days", 8)
59
- el = addTimeEl type: "weekday", datetime: before.toISOString()
60
- defer ->
61
- assert.equal getText(el), ""
62
- done()
63
-
64
- testGroup "relative weekday or date", ->
65
- testAsync "today", (done) ->
66
- now = moment()
67
- el = addTimeEl type: "weekday-or-date", datetime: now.toISOString()
68
- defer ->
69
- assert.equal getText(el), "today"
70
- done()
71
-
72
- testAsync "yesterday", (done) ->
73
- yesterday = moment().subtract("days", 1)
74
- el = addTimeEl type: "weekday-or-date", datetime: yesterday.toISOString()
75
- defer ->
76
- assert.equal getText(el), "yesterday"
77
- done()
78
-
79
- testAsync "this week", (done) ->
80
- recent = moment().subtract("days", 3)
81
- el = addTimeEl type: "weekday-or-date", datetime: recent.toISOString()
82
- defer ->
83
- assert.equal getText(el), recent.format("dddd")
84
- done()
85
-
86
- testAsync "before this week", (done) ->
87
- before = moment("#{new Date().getFullYear()}1031", "YYYYMMDD").subtract("days", 8)
88
- el = addTimeEl type: "weekday-or-date", datetime: before.toISOString()
89
- defer ->
90
- assert.equal getText(el), before.format("MMM D")
91
- done()
@@ -1,127 +0,0 @@
1
- import LocalTime from "local_time"
2
-
3
- {addTimeEl, assert, defer, getText, setText, test, testAsync, testGroup, triggerEvent} = LocalTime.TestHelpers
4
-
5
- momentMap =
6
- "%a": "ddd"
7
- "%A": "dddd"
8
- "%b": "MMM"
9
- "%B": "MMMM"
10
- "%c": "toString()"
11
- "%d": "DD"
12
- "%-d": "D"
13
- "%e": "D"
14
- "%H": "HH"
15
- "%-H": "H"
16
- "%I": "hh"
17
- "%-I": "h"
18
- "%l": "h"
19
- "%m": "MM"
20
- "%-m": "M"
21
- "%M": "mm"
22
- "%-M": "m"
23
- "%p": "A"
24
- "%P": "a"
25
- "%S": "ss"
26
- "%-S": "s"
27
- "%w": "e"
28
- "%y": "YY"
29
- "%Y": "YYYY"
30
-
31
- stubDateToLocaleString = (stubImplementation, callback) ->
32
- original = Date.prototype.toLocaleString
33
- Date.prototype.toLocaleString = stubImplementation
34
- try
35
- callback()
36
- finally
37
- Date.prototype.toLocaleString = original
38
-
39
- stubDateToString = (stubImplementation, callback) ->
40
- original = Date.prototype.toString
41
- Date.prototype.toString = stubImplementation
42
- try
43
- callback()
44
- finally
45
- Date.prototype.toString = original
46
-
47
- testGroup "strftime", ->
48
- for day in [0..30] by 6
49
- do (day) ->
50
- for hour in [0..24] by 6
51
- do (hour) ->
52
-
53
- for format, momentFormat of momentMap
54
- do (format, momentFormat) ->
55
- test "#{format} (+#{day} days, #{hour} hours)", ->
56
- now = moment().add("days", day).add("hours", hour)
57
- el = addTimeEl {format, datetime: now.toISOString()}
58
- LocalTime.process(el)
59
-
60
- assert.equal getText(el),
61
- if func = momentFormat.match(/(\w+)\(\)/)?[1]
62
- now.toDate()[func]()
63
- else
64
- now.format momentFormat
65
-
66
- test "%Z Timezone (+#{day} days, #{hour} hours)", ->
67
- now = moment().add("days", day).add("hours", hour)
68
- el = addTimeEl format: "%Z", datetime: now.toISOString()
69
- LocalTime.process(el)
70
-
71
- text = getText el
72
- assert.ok /^(\w{3,4}|UTC[\+\-]\d+)$/.test(text), "'#{text}' doesn't look like a timezone. System date: '#{new Date}'"
73
-
74
- testGroup "strftime time zones", ->
75
- for timeZone in Object.keys(LocalTime.knownEdgeCaseTimeZones)
76
- do (timeZone) ->
77
- test "edge-case time zone #{timeZone}", ->
78
- stub = -> "Thu Nov 30 2023 14:22:57 GMT-0000 (#{timeZone})"
79
-
80
- stubDateToLocaleString stub, ->
81
- el = addTimeEl format: "%Z", datetime: "2023-11-30T14:22:57Z"
82
- LocalTime.process(el)
83
-
84
- assert.equal getText(el), LocalTime.knownEdgeCaseTimeZones[timeZone]
85
-
86
- test "time zones Intl can abbreviate are parsed correctly", ->
87
- stub = (_, options) ->
88
- if options.timeZoneName == "long"
89
- "Thu Nov 30 2023 14:22:57 GMT-0800 (Alaska Daylight Time)" # not a known edge-case
90
- else if options.timeZoneName == "short"
91
- "11/30/2023, 2:22:57 PM AKDT" # possible to abbreviate
92
-
93
- stubDateToLocaleString stub, ->
94
- el = addTimeEl format: "%Z", datetime: "2023-11-30T14:22:57Z"
95
- LocalTime.process(el)
96
-
97
- assert.equal getText(el), "AKDT"
98
-
99
- test "time zones Intl can't abbreviate are parsed by our heuristic", ->
100
- dateToStringStub = -> "Sat Dec 02 2023 17:20:26 GMT-0600 (Central Standard Time)"
101
- dateToLocaleStringStub = (_, options) ->
102
- if options.timeZoneName == "long"
103
- "Thu Nov 30 2023 14:22:57 GMT+0700 (Central Twilight Time)" # not a known edge-case
104
- else if options.timeZoneName == "short"
105
- "11/30/2023, 2:22:57 PM GMT+7" # not possible to abbreviate
106
-
107
- stubDateToString dateToStringStub, ->
108
- stubDateToLocaleString dateToLocaleStringStub, ->
109
- el = addTimeEl format: "%Z", datetime: "2023-11-30T14:22:57Z"
110
- LocalTime.process(el)
111
-
112
- assert.equal getText(el), "CST"
113
-
114
- test "time zones Intl can't abbreviate and our heuristic can't parse display GMT offset", ->
115
- dateToStringStub = -> ""
116
- dateToLocaleStringStub = (_, options) ->
117
- if options.timeZoneName == "long"
118
- "Thu Nov 30 2023 14:22:57 GMT+0700 (Central Twilight Time)" # not a known edge-case
119
- else if options.timeZoneName == "short"
120
- "11/30/2023, 2:22:57 PM GMT+7" # not possible to abbreviate
121
-
122
- stubDateToString dateToStringStub, ->
123
- stubDateToLocaleString dateToLocaleStringStub, ->
124
- el = addTimeEl format: "%Z", datetime: "2023-11-30T14:22:57Z"
125
- LocalTime.process(el)
126
-
127
- assert.equal getText(el), "GMT+7"
@@ -1,46 +0,0 @@
1
- import LocalTime from "local_time"
2
-
3
- LocalTime.start()
4
-
5
- LocalTime.TestHelpers =
6
- assert: QUnit.assert
7
- testGroup: QUnit.module
8
- test: QUnit.test
9
-
10
- testAsync: (name, callback) ->
11
- QUnit.test name, (assert) ->
12
- done = assert.async()
13
- callback(done)
14
-
15
- addTimeEl: ({format, type, datetime, format24} = {}) ->
16
- format ?= "%Y"
17
- type ?= "time"
18
- datetime ?= "2013-11-12T12:13:00Z"
19
-
20
- el = document.createElement "time"
21
- el.setAttribute "data-local", type
22
- el.setAttribute "data-format", format
23
- el.setAttribute "datetime", datetime
24
- if format24 then el.setAttribute "data-format24", format24
25
-
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
- getTitle: (el) ->
38
- el.getAttribute("title")
39
-
40
- triggerEvent: (name, el = document) ->
41
- event = document.createEvent "Events"
42
- event.initEvent name, true, true
43
- el.dispatchEvent event
44
-
45
- defer: (callback) ->
46
- setTimeout(callback, 1)
@@ -1,58 +0,0 @@
1
- import LocalTime from "local_time"
2
-
3
- {addTimeEl, assert, defer, getText, setText, test, testAsync, testGroup, triggerEvent} = LocalTime.TestHelpers
4
-
5
- testGroup "time ago", ->
6
- test "a second ago", ->
7
- assertTimeAgo "a second ago", "seconds", 9
8
-
9
- test "seconds ago", ->
10
- assertTimeAgo "44 seconds ago", "seconds", 44
11
-
12
- test "a minute ago", ->
13
- assertTimeAgo "a minute ago", "seconds", 89
14
-
15
- test "minutes ago", ->
16
- assertTimeAgo "44 minutes ago", "minutes", 44
17
-
18
- test "an hour ago", ->
19
- assertTimeAgo "an hour ago", "minutes", 89
20
-
21
- test "hours ago", ->
22
- assertTimeAgo "23 hours ago", "hours", 23
23
-
24
- test "yesterday", ->
25
- time = moment().subtract("days", 1).format "h:mma"
26
- assertTimeAgo "yesterday at #{time}", "days", 1
27
-
28
- test "tomorrow", ->
29
- time = moment().add("days", 1).format "h:mma"
30
- assertTimeAgo "tomorrow at #{time}", "days", -1
31
-
32
- test "last week", ->
33
- ago = moment().subtract "days", 5
34
- day = ago.format "dddd"
35
- time = ago.format "h:mma"
36
-
37
- assertTimeAgo "#{day} at #{time}", "days", 5
38
-
39
- test "this year", ->
40
- clock = sinon.useFakeTimers(new Date(2013,11,11,11,11).getTime(), "Date")
41
- date = moment().subtract("days", 7).format "MMM D"
42
- assertTimeAgo "on #{date}", "days", 7
43
- clock.restore()
44
-
45
- test "last year", ->
46
- date = moment().subtract("days", 366).format "MMM D, YYYY"
47
- assertTimeAgo "on #{date}", "days", 366
48
-
49
- test "next year", ->
50
- date = moment().add("days", 366).format "MMM D, YYYY"
51
- assertTimeAgo "on #{date}", "days", -366
52
-
53
- assertTimeAgo = (string, unit, amount) ->
54
- el = document.getElementById "ago"
55
- el.setAttribute "data-local", "time-ago"
56
- el.setAttribute "datetime", moment().subtract(unit, amount).utc().toISOString()
57
- LocalTime.run()
58
- assert.equal getText(el), string
File without changes