mirror of
https://github.com/Gimanh/taskview-community.git
synced 2026-12-06 10:43:13 +00:00
fix: tz
This commit is contained in:
@@ -4,6 +4,8 @@ RUN apk add --no-cache curl
|
||||
|
||||
RUN npm install pm2 -g
|
||||
|
||||
ENV TZ=UTC
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY ./dist .
|
||||
|
||||
@@ -10,6 +10,7 @@ import SessionStorage from './tv-modules/auth/SessionStorage';
|
||||
import { AccountDeletion } from './tv-modules/auth/AccountDeletion';
|
||||
import { InviteEmailDispatcher } from './tv-modules/collaboration/InviteEmailDispatcher';
|
||||
import { PublicApiUrl } from './modules/public-url';
|
||||
import { ProcessTimezone } from './modules/process-timezone';
|
||||
import { validateWebhooksEnvOnStartup } from './tv-modules/webhooks/webhooks.utils';
|
||||
import { validateSsoEnvOnStartup } from './tv-modules/sso/sso.utils';
|
||||
import { validateImportEnvOnStartup } from './tv-modules/import/import.utils';
|
||||
@@ -23,6 +24,7 @@ export default class App {
|
||||
public port: number;
|
||||
|
||||
constructor(port: number) {
|
||||
ProcessTimezone.enforceOnStartup();
|
||||
LoginMethods.validateOnStartup();
|
||||
SessionStorage.validateOnStartup();
|
||||
AccountDeletion.validateOnStartup();
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { ProcessTimezone } from '../process-timezone';
|
||||
|
||||
vi.mock('../logget', () => ({ $logger: { warn: vi.fn() } }));
|
||||
|
||||
describe('ProcessTimezone', () => {
|
||||
const original = process.env.TZ;
|
||||
|
||||
afterEach(() => {
|
||||
process.env.TZ = original;
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('switches a process started in another time zone to UTC', () => {
|
||||
process.env.TZ = 'Asia/Tokyo';
|
||||
vi.spyOn(console, 'warn').mockImplementation(() => {});
|
||||
expect(new Date('2026-01-01T00:00:00Z').getHours()).toBe(9);
|
||||
|
||||
ProcessTimezone.enforceOnStartup();
|
||||
|
||||
expect(process.env.TZ).toBe('UTC');
|
||||
expect(new Date('2026-01-01T00:00:00Z').getHours()).toBe(0);
|
||||
expect(new Date(2026, 0, 1).toISOString()).toBe('2026-01-01T00:00:00.000Z');
|
||||
});
|
||||
|
||||
it('warns that a non-UTC TZ is ignored', () => {
|
||||
process.env.TZ = 'Europe/Berlin';
|
||||
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
||||
|
||||
ProcessTimezone.enforceOnStartup();
|
||||
|
||||
expect(warn).toHaveBeenCalledWith(expect.stringContaining('TZ="Europe/Berlin" is ignored'));
|
||||
});
|
||||
|
||||
it('stays quiet when TZ is already UTC or unset', () => {
|
||||
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
||||
|
||||
process.env.TZ = 'UTC';
|
||||
ProcessTimezone.enforceOnStartup();
|
||||
delete process.env.TZ;
|
||||
ProcessTimezone.enforceOnStartup();
|
||||
|
||||
expect(warn).not.toHaveBeenCalled();
|
||||
expect(process.env.TZ).toBe('UTC');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
import { $logger } from './logget';
|
||||
|
||||
export const PROCESS_TIMEZONE = 'UTC';
|
||||
|
||||
export class ProcessTimezone {
|
||||
/**
|
||||
* Columns are TIMESTAMP without time zone, and node-postgres reads and writes
|
||||
* them in the process time zone — so the process must run in UTC no matter
|
||||
* what TZ the host or container was given.
|
||||
*/
|
||||
static enforceOnStartup(): void {
|
||||
const configured = process.env.TZ;
|
||||
if (configured && configured !== PROCESS_TIMEZONE) {
|
||||
const message = `[timezone] TZ="${configured}" is ignored - the API always runs in ${PROCESS_TIMEZONE}`;
|
||||
console.warn(message);
|
||||
$logger.warn(message);
|
||||
}
|
||||
process.env.TZ = PROCESS_TIMEZONE;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user