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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12420b2d394aeb5c3cb81891bdcfa502b0e9895e69fe4aa88078242231f553b2
4
- data.tar.gz: e2ef1068f67fef6eb2d3f27759b5b96ad9a18341cf4aaa95aed7192c7efc2056
3
+ metadata.gz: 304e5226aecac6545d71824a8210028d4400e60a69eab8fcdd0c525d24c086e1
4
+ data.tar.gz: 9e8c5286192e35ae38aa6178291a240f6f77b8cc6802f582e2700c7deada454a
5
5
  SHA512:
6
- metadata.gz: 32058c11f4410212a27522314f6d88c73a93f66c3791f2904fd1ba78b1d6e471ab9c963dd69a889b8bf190b6bbbbebf8493619f4877e96e454066dc05e7c4d3b
7
- data.tar.gz: 0f7d5b901d8a56c6d61201c87e1f719f2b15951d92de3cca021cc0b0f7bb59b7d88118b6f84a79cae07caf33d93b55923adc8d0037c1a0705af0928f9fc249ac
6
+ metadata.gz: 8533cc2d64ed31f2a154b9699ebfc427e6aef948ef414b1ab78ad045688c2b52e3d855b2fd145ed7437e2ab14a0bdc00dc1a6ad0e8c846e7f0a00545c4ea7bab
7
+ data.tar.gz: 6c2723718da2c458bb4e458873049a180cd6b46ba45905c8aaf1b098fe6f3ed02aec7085e08a92c2d695296ad277f0f0e0e30b069662c830ee75b3994632309c
@@ -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. The active Rails `Time.zone`.
62
- 3. `Lesli.config.datetime[:time_zone]` when no Rails zone is active.
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's `ApplicationLesliController` applies the authenticated user's profile zone
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
- Time.use_zone("Europe/Berlin") do
72
- LesliDate::Formatter.new("2027-01-15 15:00:00").date_time.to_s
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
- `Date2` inherits the same behavior. Existing formatter instances retain the zone
78
- selected at construction. Outside requests, jobs and console calls use their
79
- active `Time.zone`; pass `zone:` when a specific output zone is required.
80
- This changes the previous behavior where the global Lesli setting took precedence
81
- over the active Rails zone.
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:` still defaults to UTC for strings without an offset. Zone names
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
- Jobs and mailers do not run inside Core's HTTP controller callback. Always apply
90
- the recipient's `effective_time_zone` where dates are formatted. Active Job may
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
- class ReminderMailer < ApplicationMailer
112
- around_action :use_recipient_timezone
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
- These are application examples, not additional framework classes. For multiple
130
- recipients, format each recipient's content in their own zone. `Time.use_zone`
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 active Rails `Time.zone`, then `Lesli.config.datetime[:time_zone]` if no Rails
54
- zone is active. Core sets the active zone from the profile or application default.
55
- Normal Lesli calls need no zone options:
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
@@ -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
- output_zone = zone.nil? ? (Time.zone&.name || config[:time_zone]) : zone
60
- # Core applies the profile or application zone; input timestamps remain UTC.
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
 
@@ -32,6 +32,8 @@ module LesliDate
32
32
  private
33
33
 
34
34
  def resolve_zone(name)
35
+ return name if name.is_a?(ActiveSupport::TimeZone)
36
+
35
37
  zone = ActiveSupport::TimeZone[name] if name.is_a?(String)
36
38
  zone || raise(InvalidTimeZone, "Unknown time zone: #{name.inspect}")
37
39
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LesliDate
4
- VERSION = "1.1.2"
4
+ VERSION = "1.1.3"
5
5
  BUILD = "1794792297"
6
6
  end
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.2
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-16 00:00:00.000000000 Z
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