mirror of
https://github.com/home-assistant/frontend.git
synced 2025-12-24 20:55:49 +00:00
Allow to show times in the UI in the timezone of the server (#16799)
This commit is contained in:
@@ -7,7 +7,9 @@ import {
|
||||
TimeFormat,
|
||||
FirstWeekday,
|
||||
DateFormat,
|
||||
TimeZone,
|
||||
} from "../../../src/data/translation";
|
||||
import { demoConfig } from "../../../src/fake_data/demo_config";
|
||||
|
||||
let localeData: FrontendLocaleData;
|
||||
|
||||
@@ -22,6 +24,7 @@ describe("computeStateDisplay", () => {
|
||||
number_format: NumberFormat.comma_decimal,
|
||||
time_format: TimeFormat.am_pm,
|
||||
date_format: DateFormat.language,
|
||||
time_zone: TimeZone.local,
|
||||
first_weekday: FirstWeekday.language,
|
||||
};
|
||||
});
|
||||
@@ -33,7 +36,7 @@ describe("computeStateDisplay", () => {
|
||||
attributes: {},
|
||||
};
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, localeData, {}),
|
||||
computeStateDisplay(localize, stateObj, localeData, demoConfig, {}),
|
||||
"component.binary_sensor.entity_component._.state.off"
|
||||
);
|
||||
});
|
||||
@@ -47,7 +50,7 @@ describe("computeStateDisplay", () => {
|
||||
},
|
||||
};
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, localeData, {}),
|
||||
computeStateDisplay(localize, stateObj, localeData, demoConfig, {}),
|
||||
"component.binary_sensor.state.moisture.off"
|
||||
);
|
||||
});
|
||||
@@ -67,7 +70,7 @@ describe("computeStateDisplay", () => {
|
||||
},
|
||||
};
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(altLocalize, stateObj, localeData, {}),
|
||||
computeStateDisplay(altLocalize, stateObj, localeData, demoConfig, {}),
|
||||
"component.binary_sensor.state.invalid_device_class.off"
|
||||
);
|
||||
});
|
||||
@@ -81,7 +84,7 @@ describe("computeStateDisplay", () => {
|
||||
},
|
||||
};
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, localeData, {}),
|
||||
computeStateDisplay(localize, stateObj, localeData, demoConfig, {}),
|
||||
"123 m"
|
||||
);
|
||||
});
|
||||
@@ -95,7 +98,7 @@ describe("computeStateDisplay", () => {
|
||||
},
|
||||
};
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, localeData, {}),
|
||||
computeStateDisplay(localize, stateObj, localeData, demoConfig, {}),
|
||||
"1,234.5 m"
|
||||
);
|
||||
});
|
||||
@@ -109,7 +112,7 @@ describe("computeStateDisplay", () => {
|
||||
},
|
||||
};
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, localeData, {}),
|
||||
computeStateDisplay(localize, stateObj, localeData, demoConfig, {}),
|
||||
"1,234.5"
|
||||
);
|
||||
});
|
||||
@@ -129,7 +132,7 @@ describe("computeStateDisplay", () => {
|
||||
},
|
||||
};
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(altLocalize, stateObj, localeData, {}),
|
||||
computeStateDisplay(altLocalize, stateObj, localeData, demoConfig, {}),
|
||||
"state.default.unknown"
|
||||
);
|
||||
});
|
||||
@@ -149,7 +152,7 @@ describe("computeStateDisplay", () => {
|
||||
},
|
||||
};
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(altLocalize, stateObj, localeData, {}),
|
||||
computeStateDisplay(altLocalize, stateObj, localeData, demoConfig, {}),
|
||||
"state.default.unavailable"
|
||||
);
|
||||
});
|
||||
@@ -169,7 +172,7 @@ describe("computeStateDisplay", () => {
|
||||
attributes: {},
|
||||
};
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(altLocalize, stateObj, localeData, {}),
|
||||
computeStateDisplay(altLocalize, stateObj, localeData, demoConfig, {}),
|
||||
"component.sensor.entity_component._.state.custom_state"
|
||||
);
|
||||
});
|
||||
@@ -191,14 +194,14 @@ describe("computeStateDisplay", () => {
|
||||
};
|
||||
it("Uses am/pm time format", () => {
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, localeData, {}),
|
||||
computeStateDisplay(localize, stateObj, localeData, demoConfig, {}),
|
||||
"November 18, 2017 at 11:12 PM"
|
||||
);
|
||||
});
|
||||
it("Uses 24h time format", () => {
|
||||
localeData.time_format = TimeFormat.twenty_four;
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, localeData, {}),
|
||||
computeStateDisplay(localize, stateObj, localeData, demoConfig, {}),
|
||||
"November 18, 2017 at 23:12"
|
||||
);
|
||||
});
|
||||
@@ -220,7 +223,7 @@ describe("computeStateDisplay", () => {
|
||||
},
|
||||
};
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, localeData, {}),
|
||||
computeStateDisplay(localize, stateObj, localeData, demoConfig, {}),
|
||||
"November 18, 2017"
|
||||
);
|
||||
});
|
||||
@@ -243,14 +246,14 @@ describe("computeStateDisplay", () => {
|
||||
it("Uses am/pm time format", () => {
|
||||
localeData.time_format = TimeFormat.am_pm;
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, localeData, {}),
|
||||
computeStateDisplay(localize, stateObj, localeData, demoConfig, {}),
|
||||
"11:12 PM"
|
||||
);
|
||||
});
|
||||
it("Uses 24h time format", () => {
|
||||
localeData.time_format = TimeFormat.twenty_four;
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, localeData, {}),
|
||||
computeStateDisplay(localize, stateObj, localeData, demoConfig, {}),
|
||||
"23:12"
|
||||
);
|
||||
});
|
||||
@@ -277,6 +280,7 @@ describe("computeStateDisplay", () => {
|
||||
localize,
|
||||
stateObj,
|
||||
localeData,
|
||||
demoConfig,
|
||||
{},
|
||||
"2021-07-04 15:40:03"
|
||||
),
|
||||
@@ -290,6 +294,7 @@ describe("computeStateDisplay", () => {
|
||||
localize,
|
||||
stateObj,
|
||||
localeData,
|
||||
demoConfig,
|
||||
{},
|
||||
"2021-07-04 15:40:03"
|
||||
),
|
||||
@@ -314,7 +319,14 @@ describe("computeStateDisplay", () => {
|
||||
},
|
||||
};
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, localeData, {}, "2021-07-04"),
|
||||
computeStateDisplay(
|
||||
localize,
|
||||
stateObj,
|
||||
localeData,
|
||||
demoConfig,
|
||||
{},
|
||||
"2021-07-04"
|
||||
),
|
||||
"July 4, 2021"
|
||||
);
|
||||
});
|
||||
@@ -337,14 +349,28 @@ describe("computeStateDisplay", () => {
|
||||
it("Uses am/pm time format", () => {
|
||||
localeData.time_format = TimeFormat.am_pm;
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, localeData, {}, "17:05:07"),
|
||||
computeStateDisplay(
|
||||
localize,
|
||||
stateObj,
|
||||
localeData,
|
||||
demoConfig,
|
||||
{},
|
||||
"17:05:07"
|
||||
),
|
||||
"5:05 PM"
|
||||
);
|
||||
});
|
||||
it("Uses 24h time format", () => {
|
||||
localeData.time_format = TimeFormat.twenty_four;
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, localeData, {}, "17:05:07"),
|
||||
computeStateDisplay(
|
||||
localize,
|
||||
stateObj,
|
||||
localeData,
|
||||
demoConfig,
|
||||
{},
|
||||
"17:05:07"
|
||||
),
|
||||
"17:05"
|
||||
);
|
||||
});
|
||||
@@ -363,7 +389,7 @@ describe("computeStateDisplay", () => {
|
||||
attributes: {},
|
||||
};
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(altLocalize, stateObj, localeData, {}),
|
||||
computeStateDisplay(altLocalize, stateObj, localeData, demoConfig, {}),
|
||||
"state.default.unavailable"
|
||||
);
|
||||
});
|
||||
@@ -378,7 +404,7 @@ describe("computeStateDisplay", () => {
|
||||
attributes: {},
|
||||
};
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(altLocalize, stateObj, localeData, {}),
|
||||
computeStateDisplay(altLocalize, stateObj, localeData, demoConfig, {}),
|
||||
"My Custom State"
|
||||
);
|
||||
});
|
||||
@@ -396,7 +422,7 @@ describe("computeStateDisplay", () => {
|
||||
},
|
||||
};
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, localeData, entities),
|
||||
computeStateDisplay(localize, stateObj, localeData, demoConfig, entities),
|
||||
"component.custom_integration.entity.sensor.custom_translation.state.custom_state"
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user