fix: show snapshot time in browser time zone (#101)
This commit was merged in pull request #102.
This commit is contained in:
@@ -72,6 +72,9 @@ function renderEvents(accountId: string, searches: string[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe("Upcoming event date filters", () => {
|
describe("Upcoming event date filters", () => {
|
||||||
|
afterEach(() => {
|
||||||
|
vi.useRealTimers();
|
||||||
|
});
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// Pin "today": the test picks today + 10 days, which must be inside the visible calendar grid.
|
// Pin "today": the test picks today + 10 days, which must be inside the visible calendar grid.
|
||||||
// Real dates can push it beyond the grid (e.g. 2026-10-23 -> 2 November).
|
// Real dates can push it beyond the grid (e.g. 2026-10-23 -> 2 November).
|
||||||
@@ -235,6 +238,10 @@ describe("Upcoming event date filters", () => {
|
|||||||
it.each(["account-1", "all"])(
|
it.each(["account-1", "all"])(
|
||||||
"applies dates only on submit, restores URL dates, and resets from empty results for %s",
|
"applies dates only on submit, restores URL dates, and resets from empty results for %s",
|
||||||
async (accountId) => {
|
async (accountId) => {
|
||||||
|
// Pin "today" mid-month so "today + 10 days" stays in the calendar's
|
||||||
|
// visible month regardless of the real date.
|
||||||
|
vi.useFakeTimers({ toFake: ["Date"] });
|
||||||
|
vi.setSystemTime(new Date("2026-10-15T12:00:00+03:00"));
|
||||||
const [defaultFrom, defaultTo] = defaultPeriod();
|
const [defaultFrom, defaultTo] = defaultPeriod();
|
||||||
const searches: string[] = [];
|
const searches: string[] = [];
|
||||||
server.use(
|
server.use(
|
||||||
|
|||||||
@@ -413,7 +413,9 @@ describe("stock page", () => {
|
|||||||
expect(await screen.findByText("Продажа")).toBeVisible();
|
expect(await screen.findByText("Продажа")).toBeVisible();
|
||||||
expect(screen.getByText("2 шт.")).toBeVisible();
|
expect(screen.getByText("2 шт.")).toBeVisible();
|
||||||
expect(screen.getByText("Цена: 100 ₽")).toBeVisible();
|
expect(screen.getByText("Цена: 100 ₽")).toBeVisible();
|
||||||
expect(screen.getByText(/02.01.2022, 10:00 UTC/)).toBeVisible();
|
const snapshotTime = new Intl.DateTimeFormat("ru-RU", { dateStyle: "short", timeStyle: "short" });
|
||||||
|
const operationTime = snapshotTime.format(new Date("2022-01-02T10:00:00Z"));
|
||||||
|
expect(screen.getByText(operationTime, { exact: false })).toBeVisible();
|
||||||
expect(
|
expect(
|
||||||
requests.some(
|
requests.some(
|
||||||
url =>
|
url =>
|
||||||
|
|||||||
@@ -93,7 +93,9 @@ describe("stock search", () => {
|
|||||||
expect(
|
expect(
|
||||||
await screen.findByRole("link", { name: /Сбербанк/ }),
|
await screen.findByRole("link", { name: /Сбербанк/ }),
|
||||||
).toHaveAttribute("href", "/stocks/e6123145-9665-43e0-8413-cd61b8aa9b13");
|
).toHaveAttribute("href", "/stocks/e6123145-9665-43e0-8413-cd61b8aa9b13");
|
||||||
expect(screen.getByText("Список получен 10.10.2026, 10:00")).toBeVisible();
|
const snapshotTime = new Intl.DateTimeFormat("ru-RU", { dateStyle: "short", timeStyle: "short" });
|
||||||
|
const fetchedAt = snapshotTime.format(new Date("2026-10-10T10:00:00Z"));
|
||||||
|
expect(screen.getByText(`Список получен ${fetchedAt}`)).toBeVisible();
|
||||||
expect(screen.getByText("Лот: 10 шт.")).toBeVisible();
|
expect(screen.getByText("Лот: 10 шт.")).toBeVisible();
|
||||||
expect(screen.getByText("ISIN: RU0009029540")).toBeVisible();
|
expect(screen.getByText("ISIN: RU0009029540")).toBeVisible();
|
||||||
expect(screen.getAllByText("Мосбиржа")[0]).toBeVisible();
|
expect(screen.getAllByText("Мосбиржа")[0]).toBeVisible();
|
||||||
|
|||||||
@@ -420,7 +420,7 @@ const ru = {
|
|||||||
next: "Далее",
|
next: "Далее",
|
||||||
noInstrument: "Без инструмента",
|
noInstrument: "Без инструмента",
|
||||||
noMoney: "Без движения денег",
|
noMoney: "Без движения денег",
|
||||||
occurredAt: "{{date}} UTC",
|
occurredAt: "{{date}}",
|
||||||
open: "Открыть журнал",
|
open: "Открыть журнал",
|
||||||
operationType: {
|
operationType: {
|
||||||
buy: "Покупка",
|
buy: "Покупка",
|
||||||
@@ -632,7 +632,7 @@ const ru = {
|
|||||||
position: "Моя позиция",
|
position: "Моя позиция",
|
||||||
previous: "Назад",
|
previous: "Назад",
|
||||||
price: "Цена",
|
price: "Цена",
|
||||||
priceAt: "Цена на {{date}} UTC",
|
priceAt: "Цена на {{date}}",
|
||||||
priceTable: "Цены в таблице",
|
priceTable: "Цены в таблице",
|
||||||
priceTableHint: "Дневные закрытия · записей: {{count}} · сначала новые",
|
priceTableHint: "Дневные закрытия · записей: {{count}} · сначала новые",
|
||||||
priceUnavailable: "Цена недоступна",
|
priceUnavailable: "Цена недоступна",
|
||||||
@@ -721,7 +721,7 @@ const ru = {
|
|||||||
SHARE_TYPE_GDR: "Депозитарная расписка",
|
SHARE_TYPE_GDR: "Депозитарная расписка",
|
||||||
SHARE_TYPE_PREFERRED: "Привилегированная акция",
|
SHARE_TYPE_PREFERRED: "Привилегированная акция",
|
||||||
},
|
},
|
||||||
snapshotAt: "Позиция на {{date}} UTC",
|
snapshotAt: "Позиция на {{date}}",
|
||||||
trading: {
|
trading: {
|
||||||
SECURITY_TRADING_STATUS_BREAK_IN_TRADING: "Перерыв в торгах",
|
SECURITY_TRADING_STATUS_BREAK_IN_TRADING: "Перерыв в торгах",
|
||||||
SECURITY_TRADING_STATUS_CLOSING_AUCTION: "Аукцион закрытия",
|
SECURITY_TRADING_STATUS_CLOSING_AUCTION: "Аукцион закрытия",
|
||||||
|
|||||||
@@ -12,9 +12,16 @@ describe("shared display helpers", () => {
|
|||||||
expect(formatDate("2027-09-10")).toBe("10.09.2027");
|
expect(formatDate("2027-09-10")).toBe("10.09.2027");
|
||||||
expect(formatDate("2024-02-29")).toBe("29.02.2024");
|
expect(formatDate("2024-02-29")).toBe("29.02.2024");
|
||||||
expect(formatDate("2027-09-10T00:30:00+03:00")).toBe("09.09.2027");
|
expect(formatDate("2027-09-10T00:30:00+03:00")).toBe("09.09.2027");
|
||||||
expect(formatSnapshotTime("2027-09-10T00:30:00+03:00")).toBe(
|
});
|
||||||
"09.09.2027, 21:30",
|
it("formats snapshot time in the browser time zone", () => {
|
||||||
);
|
const instant = "2027-09-10T00:30:00+03:00";
|
||||||
|
|
||||||
|
const expected = new Intl.DateTimeFormat("ru-RU", {
|
||||||
|
dateStyle: "short",
|
||||||
|
timeStyle: "short",
|
||||||
|
}).format(new Date(instant));
|
||||||
|
|
||||||
|
expect(formatSnapshotTime(instant)).toBe(expected);
|
||||||
});
|
});
|
||||||
it("formats decimal strings without financial arithmetic", () => {
|
it("formats decimal strings without financial arithmetic", () => {
|
||||||
expect(formatMoney({ currency: "RUB", value: "-1234567.89" })).toBe(
|
expect(formatMoney({ currency: "RUB", value: "-1234567.89" })).toBe(
|
||||||
|
|||||||
@@ -61,10 +61,10 @@ function formatMoney(
|
|||||||
return `${formatDecimal(decimal)} ${currency}`;
|
return `${formatDecimal(decimal)} ${currency}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Без timeZone Intl берёт часовой пояс браузера пользователя.
|
||||||
const snapshotFormatter = new Intl.DateTimeFormat("ru-RU", {
|
const snapshotFormatter = new Intl.DateTimeFormat("ru-RU", {
|
||||||
dateStyle: "short",
|
dateStyle: "short",
|
||||||
timeStyle: "short",
|
timeStyle: "short",
|
||||||
timeZone: "UTC",
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function formatSnapshotTime(value: string): string {
|
function formatSnapshotTime(value: string): string {
|
||||||
|
|||||||
Reference in New Issue
Block a user