|
1 | 1 | import "reflect-metadata" |
| 2 | +import { expect } from "chai" |
2 | 3 | import { |
3 | | - createTestingConnections, |
4 | 4 | closeTestingConnections, |
| 5 | + createTestingConnections, |
5 | 6 | reloadTestingDatabases, |
6 | | -} from "../../utils/test-utils" |
7 | | -import { DataSource } from "../../../src" |
| 7 | +} from "../../../utils/test-utils" |
8 | 8 | import { Event } from "./entity/Event" |
9 | | -import { after, before } from "mocha" |
10 | | -import { expect } from "chai" |
| 9 | +import { DataSource } from "../../../../src" |
11 | 10 |
|
12 | | -describe("github issues > #11515 DateUtils.mixedDateToDateString should support UTC", () => { |
| 11 | +describe("columns > date utc flag", () => { |
13 | 12 | let originalTZ: string | undefined |
14 | 13 | let connections: DataSource[] |
15 | 14 |
|
16 | 15 | before(async () => { |
17 | 16 | originalTZ = process.env.TZ |
18 | 17 | process.env.TZ = "America/New_York" |
19 | 18 | connections = await createTestingConnections({ |
20 | | - entities: [__dirname + "/entity/*{.js,.ts}"], |
| 19 | + entities: [Event], |
21 | 20 | }) |
22 | 21 | }) |
23 | 22 |
|
24 | 23 | after(async () => { |
25 | 24 | process.env.TZ = originalTZ |
26 | 25 | await closeTestingConnections(connections) |
27 | 26 | }) |
| 27 | + |
28 | 28 | beforeEach(() => reloadTestingDatabases(connections)) |
29 | 29 |
|
30 | | - it("should save the date column in UTC when the utc flag is true", () => |
| 30 | + it("should save date columns in UTC when utc flag is true and in local timezone when false", () => |
31 | 31 | Promise.all( |
32 | 32 | connections.map(async (connection) => { |
33 | 33 | const event = new Event() |
34 | | - const utc = new Date(Date.UTC(2025, 5, 1)) |
| 34 | + const testDate = new Date(Date.UTC(2025, 5, 1)) // 2025-06-01 in UTC |
35 | 35 |
|
36 | | - event.localDate = utc |
37 | | - event.utcDate = utc |
| 36 | + event.localDate = testDate |
| 37 | + event.utcDate = testDate |
38 | 38 |
|
39 | | - const saveEvent = await connection.manager.save(event) |
| 39 | + const savedEvent = await connection.manager.save(event) |
40 | 40 | const result = await connection.manager.findOneBy(Event, { |
41 | | - id: saveEvent.id, |
| 41 | + id: savedEvent.id, |
42 | 42 | }) |
43 | 43 |
|
| 44 | + // UTC flag true: should save as 2025-06-01 (UTC date) |
44 | 45 | expect(result!.utcDate).to.equal("2025-06-01") |
| 46 | + // UTC flag false (default): should save as 2025-05-31 (local timezone) |
45 | 47 | expect(result!.localDate).to.equal("2025-05-31") |
46 | 48 | }), |
47 | 49 | )) |
|
0 commit comments