tsukimoji 0.2.0 → 0.3.0
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/README.md +1 -0
- data/lib/tsukimoji.rb +38 -13
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 859e0295728438790d6d6b32ec895f2392ab4c6542f117938552b4399948fa53
|
|
4
|
+
data.tar.gz: 8ed389f6ffc23855ec35bee715323b0a49741d3ca22e977efe777696f88f12bb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 18c2ccb4c75fc9c07abc03d05fe88f3a1f72bec1858f145c5185be2b5808ddecf271d1b65dd4b2ec1c0899157a3d98fd2aee64e719a59ca27c64c353391d014a
|
|
7
|
+
data.tar.gz: 1a042009eaa4084aed001b0680ceba2d04e3bc4db99b7162edfd458325d2744406fe586db81d056fecf0dee87074d38c13fdb0fe95045f56f4a29c67e35b53ae
|
data/README.md
CHANGED
data/lib/tsukimoji.rb
CHANGED
|
@@ -35,6 +35,8 @@ module Tsukimoji
|
|
|
35
35
|
MONTH_NAMES = %w[January February March April May June July
|
|
36
36
|
August September October November December].freeze
|
|
37
37
|
|
|
38
|
+
DAY_NAMES = %w[sunday monday tuesday wednesday thursday friday saturday].freeze
|
|
39
|
+
|
|
38
40
|
# Immutable result of a phase calculation.
|
|
39
41
|
Phase = Struct.new(:emoji, :name, :age_days, :illumination, keyword_init: true) do
|
|
40
42
|
def to_s
|
|
@@ -50,12 +52,17 @@ module Tsukimoji
|
|
|
50
52
|
class << self
|
|
51
53
|
# Returns a Tsukimoji::Phase for the given time (defaults to now, UTC).
|
|
52
54
|
# Pass faces: true to get 🌚 and 🌝 for new and full moons.
|
|
55
|
+
#
|
|
56
|
+
# The phase is the one for the time's UTC day, the same as calendar: new
|
|
57
|
+
# moon, first quarter, full moon and last quarter only on the day they
|
|
58
|
+
# happen, crescent or gibbous on the days in between. age_days and
|
|
59
|
+
# illumination are for the exact moment.
|
|
53
60
|
def phase(time = Time.now.utc, faces: false)
|
|
54
61
|
time = time.utc
|
|
55
62
|
elapsed_seconds = time.to_f - KNOWN_NEW_MOON.to_f
|
|
56
63
|
cycles = elapsed_seconds / SYNODIC_MONTH_SECONDS
|
|
57
64
|
age = ((cycles % 1) + 1) % 1
|
|
58
|
-
index = ((
|
|
65
|
+
index, = day_phase(Time.utc(time.year, time.month, time.day))
|
|
59
66
|
illumination = (1 - Math.cos(age * 2 * Math::PI)) / 2
|
|
60
67
|
|
|
61
68
|
data = PHASES[index]
|
|
@@ -91,17 +98,13 @@ module Tsukimoji
|
|
|
91
98
|
|
|
92
99
|
(first..last).map do |day|
|
|
93
100
|
day_start = Time.utc(day.year, day.month, day.day)
|
|
94
|
-
|
|
95
|
-
n = ((day_start.to_f + 86_400 - KNOWN_NEW_MOON.to_f) / QUARTER_SECONDS).ceil - 1
|
|
96
|
-
event = KNOWN_NEW_MOON + (n * QUARTER_SECONDS)
|
|
97
|
-
is_event = event >= day_start
|
|
98
|
-
index = ((n % 4) * 2) + (is_event ? 0 : 1)
|
|
101
|
+
index, event = day_phase(day_start)
|
|
99
102
|
noon = phase(day_start + 43_200)
|
|
100
103
|
CalendarDay.new(
|
|
101
104
|
date: day,
|
|
102
105
|
emoji: (faces && FACES[index]) || PHASES[index][:emoji],
|
|
103
106
|
name: PHASES[index][:name],
|
|
104
|
-
event_time:
|
|
107
|
+
event_time: event,
|
|
105
108
|
age_days: noon.age_days,
|
|
106
109
|
illumination: noon.illumination
|
|
107
110
|
)
|
|
@@ -136,23 +139,30 @@ module Tsukimoji
|
|
|
136
139
|
"
|
|
137
140
|
end
|
|
138
141
|
|
|
139
|
-
# The calendar as plain text: a
|
|
140
|
-
#
|
|
141
|
-
|
|
142
|
+
# The calendar as plain text: a grid per month, followed by that month's
|
|
143
|
+
# exact new moon, quarter and full moon times. Weeks start on Sunday; pass
|
|
144
|
+
# week_start: :monday (or any day name) to change that, and
|
|
145
|
+
# numbers: false for a grid of just the emoji, without day numbers.
|
|
146
|
+
def calendar_text(from, to = nil, faces: false, numbers: true, week_start: :sunday)
|
|
147
|
+
first_day = DAY_NAMES.index(week_start.to_s.downcase)
|
|
148
|
+
raise ArgumentError, "week_start must be a day name, got #{week_start}" if first_day.nil?
|
|
149
|
+
|
|
150
|
+
headings = Array.new(7) { |i| DAY_NAMES[(first_day + i) % 7][0, 2].capitalize }
|
|
142
151
|
months = calendar(from, to, faces: faces).group_by { |d| [d.date.year, d.date.month] }
|
|
143
152
|
|
|
144
153
|
blocks = months.map do |(year, month), days|
|
|
145
154
|
length = Date.new(year, month, -1).day
|
|
146
|
-
offset = Date.new(year, month, 1).
|
|
155
|
+
offset = (Date.new(year, month, 1).wday - first_day) % 7
|
|
147
156
|
cells = Array.new(offset + length)
|
|
148
157
|
days.each { |d| cells[offset + d.date.day - 1] = d }
|
|
149
158
|
|
|
150
|
-
|
|
159
|
+
header = headings.map { |h| numbers ? " #{h}" : h }.join(" ")
|
|
160
|
+
lines = ["#{MONTH_NAMES[month - 1]} #{year}", header]
|
|
151
161
|
cells.each_slice(7) do |week|
|
|
152
162
|
week.pop until week.empty? || week.last
|
|
153
163
|
next if week.empty?
|
|
154
164
|
|
|
155
|
-
lines << week.map { |d| d
|
|
165
|
+
lines << week.map { |d| text_cell(d, numbers) }.join(" ")
|
|
156
166
|
end
|
|
157
167
|
events = days.select(&:event_time)
|
|
158
168
|
unless events.empty?
|
|
@@ -173,6 +183,15 @@ module Tsukimoji
|
|
|
173
183
|
|
|
174
184
|
private
|
|
175
185
|
|
|
186
|
+
# The phase of the UTC day starting at +day_start+: [phase index, event time or nil].
|
|
187
|
+
def day_phase(day_start)
|
|
188
|
+
# The last principal phase before the end of this day.
|
|
189
|
+
n = ((day_start.to_f + 86_400 - KNOWN_NEW_MOON.to_f) / QUARTER_SECONDS).ceil - 1
|
|
190
|
+
event = KNOWN_NEW_MOON + (n * QUARTER_SECONDS)
|
|
191
|
+
is_event = event >= day_start
|
|
192
|
+
[((n % 4) * 2) + (is_event ? 0 : 1), is_event ? event : nil]
|
|
193
|
+
end
|
|
194
|
+
|
|
176
195
|
# "2026", "2026-10", "2026-10-04", 2026, a Date or a Time -> [first day, last day].
|
|
177
196
|
def span(value)
|
|
178
197
|
case value
|
|
@@ -196,6 +215,12 @@ module Tsukimoji
|
|
|
196
215
|
[Date.new(year, 1, 1), Date.new(year, 12, 31)]
|
|
197
216
|
end
|
|
198
217
|
|
|
218
|
+
def text_cell(day, numbers)
|
|
219
|
+
return numbers ? " " : " " if day.nil?
|
|
220
|
+
|
|
221
|
+
numbers ? "#{day.date.day.to_s.rjust(2)} #{day.emoji}" : day.emoji
|
|
222
|
+
end
|
|
223
|
+
|
|
199
224
|
# "2026-10-04T00:02Z": event times are only accurate to minutes at best.
|
|
200
225
|
def minute_iso(time)
|
|
201
226
|
time.utc.strftime("%Y-%m-%dT%H:%MZ")
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tsukimoji
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sam Lehman
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-11-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: tsukiMOJi computes the current (or any) lunar phase and returns the matching
|
|
14
14
|
emoji, phase name, age in days, and illumination fraction.
|