deno.land / std@0.224.0 / datetime / format_test.ts
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.import { assertEquals } from "../assert/mod.ts";import { format } from "./format.ts";
Deno.test({ name: "format()", fn: () => { // 00 hours assertEquals( "00:00:00", format(new Date("2019-01-01T00:00:00"), "HH:mm:ss"), ); assertEquals( "01:00:00", format(new Date("2019-01-01T01:00:00"), "HH:mm:ss"), ); assertEquals( "13:00:00", format(new Date("2019-01-01T13:00:00"), "HH:mm:ss"), );
// 12 hours assertEquals( "12:00:00", format(new Date("2019-01-01T00:00:00"), "hh:mm:ss"), ); assertEquals( "01:00:00", format(new Date("2019-01-01T01:00:00"), "hh:mm:ss"), ); assertEquals( "01:00:00", format(new Date("2019-01-01T13:00:00"), "hh:mm:ss"), );
// milliseconds assertEquals( "13:00:00.000", format(new Date("2019-01-01T13:00:00"), "HH:mm:ss.SSS"), ); assertEquals( "13:00:00.000", format(new Date("2019-01-01T13:00:00.000"), "HH:mm:ss.SSS"), ); assertEquals( "13:00:00.123", format(new Date("2019-01-01T13:00:00.123"), "HH:mm:ss.SSS"), );
// day period assertEquals( "00:00:00 AM", format(new Date("2019-01-01T00:00:00"), "HH:mm:ss a"), ); assertEquals( "12:00:00 AM", format(new Date("2019-01-01T00:00:00"), "hh:mm:ss a"), ); assertEquals( "01:00:00 AM", format(new Date("2019-01-01T01:00:00"), "HH:mm:ss a"), ); assertEquals( "01:00:00 AM", format(new Date("2019-01-01T01:00:00"), "hh:mm:ss a"), ); assertEquals( "01:00:00 PM", format(new Date("2019-01-01T13:00:00"), "hh:mm:ss a"), ); assertEquals( "21:00:00 PM", format(new Date("2019-01-01T21:00:00"), "HH:mm:ss a"), ); assertEquals( "09:00:00 PM", format(new Date("2019-01-01T21:00:00"), "hh:mm:ss a"), );
// quoted literal assertEquals( format(new Date(2019, 0, 20), "'today:' yyyy-MM-dd"), "today: 2019-01-20", );
assertEquals( format(new Date("2019-01-09T21:09:09"), "H:m:s yy-M-d"), "21:9:9 19-1-9", );
assertEquals( "13:00:00.00", format(new Date("2019-01-01T13:00:00.000"), "HH:mm:ss.SS"), );
assertEquals( "13:00:00.0", format(new Date("2019-01-01T13:00:00.000"), "HH:mm:ss.S"), );
assertEquals( "1", format(new Date("2019-01-01T13:00:00.000"), "h"), );
assertEquals( "2019-01-01 04:00:00.000", format( new Date("2019-01-01T13:00:00.000+09:00"), "yyyy-MM-dd HH:mm:ss.SSS", { utc: true }, ), );
assertEquals( "2019-01-01 18:00:00.000", format( new Date("2019-01-01T13:00:00.000-05:00"), "yyyy-MM-dd HH:mm:ss.SSS", { utc: true }, ), ); },});
Version Info