lesli_date 1.1.2 → 1.1.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/docs/about/configuration.md +22 -60
- data/docs/api/parsing.md +3 -3
- data/lib/lesli_date/context.rb +20 -0
- data/lib/lesli_date/formatter.rb +3 -2
- data/lib/lesli_date/parser.rb +2 -0
- data/lib/lesli_date/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 304e5226aecac6545d71824a8210028d4400e60a69eab8fcdd0c525d24c086e1
|
|
4
|
+
data.tar.gz: 9e8c5286192e35ae38aa6178291a240f6f77b8cc6802f582e2700c7deada454a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8533cc2d64ed31f2a154b9699ebfc427e6aef948ef414b1ab78ad045688c2b52e3d855b2fd145ed7437e2ab14a0bdc00dc1a6ad0e8c846e7f0a00545c4ea7bab
|
|
7
|
+
data.tar.gz: 6c2723718da2c458bb4e458873049a180cd6b46ba45905c8aaf1b098fe6f3ed02aec7085e08a92c2d695296ad277f0f0e0e30b069662c830ee75b3994632309c
|
data/docs/about/configuration.md
CHANGED
|
@@ -57,80 +57,42 @@ that behavior. Native formatting exceptions are exposed as `InvalidFormat`.
|
|
|
57
57
|
|
|
58
58
|
Output zone precedence is:
|
|
59
59
|
|
|
60
|
-
1. An explicit `zone:` argument.
|
|
61
|
-
2.
|
|
62
|
-
3. `Lesli.config.datetime[:time_zone]
|
|
60
|
+
1. An explicit `zone:` argument (an IANA name or `ActiveSupport::TimeZone`).
|
|
61
|
+
2. `LesliDate.time_zone` for the current execution context.
|
|
62
|
+
3. `Lesli.config.datetime[:time_zone]`.
|
|
63
|
+
4. The active Rails `Time.zone`, then UTC.
|
|
63
64
|
|
|
64
|
-
Core
|
|
65
|
-
with `Time.use_zone` for each request, including services and views. If the profile
|
|
66
|
-
has no zone, Core uses the Lesli initializer, then the Rails application timezone.
|
|
67
|
-
Login and browser detection do not set the timezone. LesliDate reads the active
|
|
68
|
-
Rails zone without accessing the user or HTTP session directly.
|
|
65
|
+
Core assigns the profile zone once per request:
|
|
69
66
|
|
|
70
67
|
```ruby
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
# => "15/01/2027 16:00", with the initializer above
|
|
74
|
-
end
|
|
68
|
+
LesliDate.time_zone = current_user.effective_timezone
|
|
69
|
+
Date2.new(event.start_at).date_time.to_s
|
|
75
70
|
```
|
|
76
71
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
72
|
+
The context uses `ActiveSupport::CurrentAttributes`; Rails clears it around
|
|
73
|
+
requests and jobs, including failures. It does not change `Time.zone`. Outside
|
|
74
|
+
the Rails executor (for example, a standalone script), clear it explicitly with
|
|
75
|
+
`LesliDate.time_zone = nil` when finished, or pass `zone:` to each formatter.
|
|
76
|
+
|
|
77
|
+
`current_user.effective_timezone` falls back to the Lesli initializer, then the
|
|
78
|
+
Rails application timezone. Existing formatter instances retain their selected
|
|
79
|
+
zone. Login does not store a timezone in the session.
|
|
82
80
|
|
|
83
|
-
`input_zone:`
|
|
84
|
-
are validated during construction; unknown zones or no available output zone
|
|
81
|
+
`input_zone:` defaults to UTC for strings without an offset. Unknown zones
|
|
85
82
|
raise `LesliDate::InvalidTimeZone`. Database storage remains UTC.
|
|
86
83
|
|
|
87
84
|
## Jobs and emails
|
|
88
85
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
carry the enqueueing context's timezone, but that can belong to a different user.
|
|
92
|
-
Do not rely on it for recipient-specific output.
|
|
93
|
-
|
|
94
|
-
```ruby
|
|
95
|
-
class ExportJob < ApplicationJob
|
|
96
|
-
def perform(user_id)
|
|
97
|
-
user = Lesli::User.find(user_id)
|
|
98
|
-
|
|
99
|
-
Time.use_zone(user.effective_time_zone) do
|
|
100
|
-
# Build the export here so services and Date2 use the recipient's zone.
|
|
101
|
-
ExportService.new(user).create
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
For emails, wrap the mailer action so template rendering uses the recipient's
|
|
108
|
-
zone, including when delivery is queued:
|
|
86
|
+
Pass the recipient's zone where dates are formatted, including in queued jobs
|
|
87
|
+
and mailer templates. Neither a session nor a controller callback is needed:
|
|
109
88
|
|
|
110
89
|
```ruby
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
def reminder
|
|
115
|
-
@event = params[:event]
|
|
116
|
-
mail(to: params[:recipient].email, subject: "Event reminder")
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
private
|
|
120
|
-
|
|
121
|
-
def use_recipient_timezone(&action)
|
|
122
|
-
Time.use_zone(params[:recipient].effective_time_zone, &action)
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
ReminderMailer.with(recipient: user, event: event).reminder.deliver_later
|
|
90
|
+
# Inside a job, service, or mailer template with the recipient available:
|
|
91
|
+
Date2.new(event.start_at, zone: recipient.effective_timezone).date_time.to_s
|
|
127
92
|
```
|
|
128
93
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
restores the previous zone even if the operation raises an exception. It does
|
|
132
|
-
not alter stored timestamps. Construct formatters inside the block; an existing
|
|
133
|
-
formatter retains the zone it was created with.
|
|
94
|
+
For multiple recipients, format each recipient's content in their own zone.
|
|
95
|
+
This does not alter stored timestamps or the Rails execution timezone.
|
|
134
96
|
|
|
135
97
|
## Native Rails translations
|
|
136
98
|
|
data/docs/api/parsing.md
CHANGED
|
@@ -50,9 +50,9 @@ range checks. Patterns apply to string inputs; temporal objects are used directl
|
|
|
50
50
|
## UTC input and active output zone
|
|
51
51
|
|
|
52
52
|
Lesli stores database timestamps in UTC. Output uses an explicit `zone:`, then
|
|
53
|
-
the
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
`LesliDate.time_zone`, the global Lesli setting, Rails' active zone, and UTC.
|
|
54
|
+
Core assigns the profile zone to `LesliDate.time_zone` once per request.
|
|
55
|
+
Without an explicit or contextual zone, formatting uses the application defaults:
|
|
56
56
|
|
|
57
57
|
```ruby
|
|
58
58
|
# With America/Guatemala and output format %d/%m/%Y %H:%M:
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "active_support"
|
|
4
|
+
require "active_support/current_attributes"
|
|
5
|
+
|
|
6
|
+
module LesliDate
|
|
7
|
+
# Rails resets CurrentAttributes around requests and jobs, including failures.
|
|
8
|
+
class Context < ActiveSupport::CurrentAttributes
|
|
9
|
+
attribute :time_zone
|
|
10
|
+
end
|
|
11
|
+
private_constant :Context
|
|
12
|
+
|
|
13
|
+
def self.time_zone
|
|
14
|
+
Context.time_zone
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.time_zone=(zone)
|
|
18
|
+
Context.time_zone = zone
|
|
19
|
+
end
|
|
20
|
+
end
|
data/lib/lesli_date/formatter.rb
CHANGED
|
@@ -32,6 +32,7 @@ Building a better future, one line of code at a time.
|
|
|
32
32
|
|
|
33
33
|
# maybe move this to a "LDate" gem?
|
|
34
34
|
|
|
35
|
+
require "lesli_date/context"
|
|
35
36
|
require "lesli_date/parser"
|
|
36
37
|
require "active_record"
|
|
37
38
|
require "i18n"
|
|
@@ -56,8 +57,8 @@ module LesliDate
|
|
|
56
57
|
# NOTE: user should be able to change this through settings table
|
|
57
58
|
# get initial datetime configuration
|
|
58
59
|
config = Lesli.config.datetime || {}
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
# An explicit zone overrides the request context and application defaults.
|
|
61
|
+
output_zone = zone || LesliDate.time_zone || config[:time_zone].presence || Time.zone&.name || "UTC"
|
|
61
62
|
@parser = Parser.new(input_zone: input_zone, zone: output_zone)
|
|
62
63
|
|
|
63
64
|
|
data/lib/lesli_date/parser.rb
CHANGED
data/lib/lesli_date/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lesli_date
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1.
|
|
4
|
+
version: 1.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- The Lesli Development Team
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -91,6 +91,7 @@ files:
|
|
|
91
91
|
- docs/images/date-logo.svg
|
|
92
92
|
- docs/navigation
|
|
93
93
|
- lib/lesli_date.rb
|
|
94
|
+
- lib/lesli_date/context.rb
|
|
94
95
|
- lib/lesli_date/engine.rb
|
|
95
96
|
- lib/lesli_date/errors.rb
|
|
96
97
|
- lib/lesli_date/formatter.rb
|