lesli_date 1.1.1 → 1.1.2

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: d64dec0455da16b095e0cb4b67fccb28fb2a3010f97dedcd97e0ac8178e272ca
4
- data.tar.gz: 1452d2bf0482a4604b26b03341312e3ebab51fdedba716807fd38457cb11162d
3
+ metadata.gz: 12420b2d394aeb5c3cb81891bdcfa502b0e9895e69fe4aa88078242231f553b2
4
+ data.tar.gz: e2ef1068f67fef6eb2d3f27759b5b96ad9a18341cf4aaa95aed7192c7efc2056
5
5
  SHA512:
6
- metadata.gz: bfc90a78e1b1cb23175cf9d3283720048ca882d7268528422ff20b169f67ba78ffe29a26599028cd6c5d0f1d5b3e60ccd84673425c7338a7f29f89feefeb568f
7
- data.tar.gz: 03e1aa63070d95b58b153413ce7c17d3d0052829f3be572d6d141863ca53d0533f370b441e6c8f6ec6bf2a028d6d46660446ac5c4809fcbed5a767a9838a3a33
6
+ metadata.gz: 32058c11f4410212a27522314f6d88c73a93f66c3791f2904fd1ba78b1d6e471ab9c963dd69a889b8bf190b6bbbbebf8493619f4877e96e454066dc05e7c4d3b
7
+ data.tar.gz: 0f7d5b901d8a56c6d61201c87e1f719f2b15951d92de3cca021cc0b0f7bb59b7d88118b6f84a79cae07caf33d93b55923adc8d0037c1a0705af0928f9fc249ac
data/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## 1.1.0 (unreleased)
4
4
 
5
+ - Respect the active Rails timezone for output, with explicit `zone:` taking priority. Document recipient-scoped formatting in jobs and mailers.
6
+
5
7
  ### Requirements
6
8
 
7
9
  - Ruby 3.3 or later; ActiveSupport and ActiveRecord 8.0.x or 8.1.x.
@@ -1,7 +1,7 @@
1
1
  # Configuration and presentation
2
2
 
3
3
  LesliDate reads `Lesli.config.datetime` from the Lesli initializer. Database
4
- timestamps are interpreted as UTC; `time_zone` controls presentation. The fluent
4
+ timestamps are interpreted as UTC; the active Rails timezone controls presentation. The fluent
5
5
  API stays the same:
6
6
 
7
7
  ```ruby
@@ -53,10 +53,84 @@ Syntax checks delegate to Ruby's `strftime`; there is no directive allowlist or
53
53
  custom pattern compiler. Directives that Ruby preserves as literal text retain
54
54
  that behavior. Native formatting exceptions are exposed as `InvalidFormat`.
55
55
 
56
- A valid output zone is required in the initializer unless supplied through
57
- `zone:`. `input_zone:` defaults to UTC and can be used for external local-time
58
- sources. Both zone names are validated during construction. Missing or unknown
59
- zones raise `LesliDate::InvalidTimeZone` rather than using the process timezone.
56
+ ## Profile timezone
57
+
58
+ Output zone precedence is:
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.
63
+
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.
69
+
70
+ ```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
75
+ ```
76
+
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.
82
+
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
85
+ raise `LesliDate::InvalidTimeZone`. Database storage remains UTC.
86
+
87
+ ## Jobs and emails
88
+
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:
109
+
110
+ ```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
127
+ ```
128
+
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.
60
134
 
61
135
  ## Native Rails translations
62
136
 
@@ -19,10 +19,10 @@ LesliDate::Formatter.new("2026/10/05 14:30", "%Y/%m/%d %H:%M")
19
19
  | `datetime` | `Time.current` | Date or instant to interpret; explicit `nil` is invalid |
20
20
  | `format` | `nil` | Native Ruby `strptime` pattern; otherwise use `DateTime.parse` |
21
21
  | `input_zone:` | `"UTC"` | Interpret date-time strings that have no offset |
22
- | `zone:` | `nil` | Presentation zone; `nil` reads `Lesli.config.datetime[:time_zone]` |
22
+ | `zone:` | `nil` | Presentation zone; `nil` uses `Time.zone`, then `Lesli.config.datetime[:time_zone]` |
23
23
  | `locale:` | `nil` | Output language; `nil` uses `I18n.locale` when rendering |
24
24
 
25
- Lesli's database timestamps are UTC. The configured zone controls output;
25
+ Lesli's database timestamps are UTC. The active Rails zone controls output;
26
26
  normal Lesli calls need no zone keywords. `input_zone:` is available for
27
27
  external sources that provide local times instead of UTC.
28
28
 
data/docs/api/parsing.md CHANGED
@@ -47,11 +47,12 @@ or a valid prefix with trailing text. LesliDate does not add complete-input
47
47
  validation, a directive allowlist, year bounds, encoding conversion, or manual
48
48
  range checks. Patterns apply to string inputs; temporal objects are used directly.
49
49
 
50
- ## UTC input and configured output
50
+ ## UTC input and active output zone
51
51
 
52
- Lesli stores database timestamps in UTC. The initializer's
53
- `Lesli.config.datetime[:time_zone]` controls presentation. Normal Lesli calls
54
- need no zone options:
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:
55
56
 
56
57
  ```ruby
57
58
  # With America/Guatemala and output format %d/%m/%Y %H:%M:
@@ -56,9 +56,8 @@ module LesliDate
56
56
  # NOTE: user should be able to change this through settings table
57
57
  # get initial datetime configuration
58
58
  config = Lesli.config.datetime || {}
59
- configured_zone = config[:time_zone]
60
- output_zone = zone.nil? ? configured_zone : zone
61
- # Lesli stores timestamps in UTC; the configured zone controls presentation.
59
+ output_zone = zone.nil? ? (Time.zone&.name || config[:time_zone]) : zone
60
+ # Core applies the profile or application zone; input timestamps remain UTC.
62
61
  @parser = Parser.new(input_zone: input_zone, zone: output_zone)
63
62
 
64
63
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LesliDate
4
- VERSION = "1.1.1"
5
- BUILD = "1790534691"
4
+ VERSION = "1.1.2"
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.1
4
+ version: 1.1.2
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-10-23 00:00:00.000000000 Z
11
+ date: 2026-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport