You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-08-07 21:23:00 +03:00
Merge branch 'develop' into sort-imports
Signed-off-by: Aaron Raimist <aaron@raim.ist>
This commit is contained in:
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { formatSeconds } from "../../src/DateUtils";
|
||||
import { formatSeconds, formatRelativeTime } from "../../src/DateUtils";
|
||||
|
||||
describe("formatSeconds", () => {
|
||||
it("correctly formats time with hours", () => {
|
||||
@@ -29,3 +29,44 @@ describe("formatSeconds", () => {
|
||||
expect(formatSeconds((60 * 60 * 0) + (60 * 31) + (0))).toBe("31:00");
|
||||
});
|
||||
});
|
||||
|
||||
describe("formatRelativeTime", () => {
|
||||
let dateSpy;
|
||||
beforeAll(() => {
|
||||
dateSpy = jest
|
||||
.spyOn(global.Date, 'now')
|
||||
// Tuesday, 2 November 2021 11:18:03 UTC
|
||||
.mockImplementation(() => 1635851883000);
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
dateSpy.mockRestore();
|
||||
});
|
||||
|
||||
it("returns hour format for events created less than 24 hours ago", () => {
|
||||
const date = new Date(2021, 10, 2, 11, 1, 23, 0);
|
||||
expect(formatRelativeTime(date)).toBe("11:01");
|
||||
});
|
||||
|
||||
it("honours the hour format setting", () => {
|
||||
const date = new Date(2021, 10, 2, 11, 1, 23, 0);
|
||||
expect(formatRelativeTime(date)).toBe("11:01");
|
||||
expect(formatRelativeTime(date, false)).toBe("11:01");
|
||||
expect(formatRelativeTime(date, true)).toBe("11:01AM");
|
||||
});
|
||||
|
||||
it("returns month and day for events created in the current year", () => {
|
||||
const date = new Date(1632567741000);
|
||||
expect(formatRelativeTime(date, true)).toBe("Sep 25");
|
||||
});
|
||||
|
||||
it("does not return a leading 0 for single digit days", () => {
|
||||
const date = new Date(1635764541000);
|
||||
expect(formatRelativeTime(date, true)).toBe("Nov 1");
|
||||
});
|
||||
|
||||
it("appends the year for events created in previous years", () => {
|
||||
const date = new Date(1604142141000);
|
||||
expect(formatRelativeTime(date, true)).toBe("Oct 31, 2020");
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user