Skip to content

Commit 2d0ac6a

Browse files
committed
feat: add $(internal:date_monthname) variable #3819
1 parent ec61abf commit 2d0ac6a

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎companion/lib/Internal/Time.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ export class InternalTime extends EventEmitter<InternalModuleFragmentEvents> imp
5555
description: 'Date (Month)',
5656
name: 'date_m',
5757
},
58+
{
59+
description: 'Date (Month name)',
60+
name: 'date_monthname',
61+
},
5862
{
5963
description: 'Date (Day)',
6064
name: 'date_d',
@@ -147,6 +151,7 @@ export class InternalTime extends EventEmitter<InternalModuleFragmentEvents> imp
147151
date_iso: `${year}-${month}-${day}`,
148152
date_y: year,
149153
date_m: month,
154+
date_monthname: now.toLocaleString(undefined, { month: 'long', timeZone: effectiveTz }),
150155
date_d: day,
151156
date_dow: parts.weekday,
152157
date_weekday: now.toLocaleString(undefined, { weekday: 'long', timeZone: effectiveTz }),

‎companion/test/Internal/Time.test.ts‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ describe('InternalTime', () => {
4141
const defs = time.getVariableDefinitions()
4242
const names = defs.map((d) => d.name)
4343

44-
expect(defs).toHaveLength(17)
44+
expect(defs).toHaveLength(18)
4545
expect(names).toEqual([
4646
'date_iso',
4747
'date_y',
4848
'date_m',
49+
'date_monthname',
4950
'date_d',
5051
'date_dow',
5152
'date_weekday',
@@ -182,6 +183,28 @@ describe('InternalTime', () => {
182183
})
183184
})
184185

186+
test('emits the month name in the configured timezone', () => {
187+
// Just after midnight UTC on 1 July: still June in New York, already July in Tokyo
188+
const now = new Date('2024-07-01T01:30:00Z')
189+
const config = { timezone: 'America/New_York' }
190+
191+
vi.setSystemTime(now)
192+
const time = new InternalTime(mockUserConfig(config))
193+
const setVariables = vi.fn<(values: VariableValues) => void>()
194+
time.on('setVariables', setVariables)
195+
196+
// Compare against the host locale's names, so the assertion is locale-independent
197+
const monthName = (m: number) =>
198+
new Date(Date.UTC(2024, m, 15)).toLocaleString(undefined, { month: 'long', timeZone: 'UTC' })
199+
200+
time.updateVariables()
201+
expect(lastValues(setVariables).date_monthname).toBe(monthName(5))
202+
203+
config.timezone = 'Asia/Tokyo'
204+
time.updateVariables()
205+
expect(lastValues(setVariables).date_monthname).toBe(monthName(6))
206+
})
207+
185208
test('exposes the resolved system timezone when none is configured', () => {
186209
const { time, setVariables } = createTime(new Date('2024-06-15T01:30:00Z'))
187210
time.updateVariables()

0 commit comments

Comments
 (0)