@@ -2,6 +2,7 @@ import {concatMap} from "@softwareventures/array";
22import type { Timestamp } from "@softwareventures/timestamp" ;
33import { normalize } from "@softwareventures/timestamp" ;
44import * as formatDate from "@softwareventures/format-date" ;
5+ import * as formatTime from "@softwareventures/format-time" ;
56import { JsDate } from "./js-date" ;
67
78/** A function that formats a {@link Timestamp} or part of a {@link Timestamp}
@@ -102,85 +103,60 @@ export const dayOfWeek = formatDate.dayOfWeek;
102103
103104/** Formats the hours portion of the specified {@link Timestamp} as a 24-hour
104105 * numeric string. */
105- export function hours ( timestamp : { readonly hours : number } ) : string {
106- return String ( timestamp . hours ) ;
107- }
106+ export const hours = formatTime . hours ;
108107
109108/** Formats the hours portion of the specified {@link Timestamp} as a 2-digit
110109 * 24-hour numeric string. */
111- export function hours2 ( timestamp : { readonly hours : number } ) : string {
112- return String ( timestamp . hours ) . padStart ( 2 , "0" ) ;
113- }
110+ export const hours2 = formatTime . hours2 ;
114111
115112/** Formats the hours portion of the specified {@link Timestamp} as a 12-hour
116113 * numeric string. */
117- export function hours12 ( timestamp : { readonly hours : number } ) : string {
118- return String ( ( 12 + ( timestamp . hours % 12 ) ) % 12 ) ;
119- }
114+ export const hours12 = formatTime . hours12 ;
120115
121116/** Formats the hours portion of the specified {@link Timestamp} as a 2-digit
122117 * 12-hour numeric string. */
123- export function hours122 ( timestamp : { readonly hours : number } ) : string {
124- return String ( ( 12 + ( timestamp . hours % 12 ) ) % 12 ) . padStart ( 2 , "0" ) ;
125- }
118+ export const hours122 = formatTime . hours122 ;
126119
127- export type AmPm = "AM" | "PM ";
120+ export { AmPm } from "@softwareventures/format-time ";
128121
129122/** Returns `"AM"` or `"PM"` depending on the hour of the specified
130123 * {@link Timestamp}. */
131- export function amPm ( timestamp : { readonly hours : number } ) : AmPm {
132- return timestamp . hours < 12 ? "AM" : "PM" ;
133- }
124+ export const amPm = formatTime . amPm ;
134125
135126/** Formats the minutes portion of the specified {@link Timestamp} as a
136127 * numeric string. */
137- export function minutes ( timestamp : { readonly minutes : number } ) : string {
138- return String ( timestamp . minutes ) ;
139- }
128+ export const minutes = formatTime . minutes ;
140129
141130/** Formats the minutes portion of the specified {@link Timestamp} as a
142131 * 2-digit numeric string. */
143- export function minutes2 ( timestamp : { readonly minutes : number } ) : string {
144- return String ( timestamp . minutes ) . padStart ( 2 , "0" ) ;
145- }
132+ export const minutes2 = formatTime . minutes2 ;
146133
147134/** Formats the seconds portion of the specified {@link Timestamp} as a
148135 * numeric string.
149136 *
150137 * Note that fractional seconds will not be rounded, so this might produce
151138 * a result similar to `"2.234"` */
152- export function seconds ( timestamp : { readonly seconds : number } ) : string {
153- return String ( timestamp . seconds ) ;
154- }
139+ export const seconds = formatTime . seconds ;
155140
156141/** Formats the seconds portion of the specified {@link Timestamp} as a
157142 * numeric string. If necessary, adds a leading zero to the whole part of the
158143 * seconds to ensure the whole part is at least two digits.
159144 *
160145 * Note that fractional seconds will not be rounded, so this might produce
161146 * a result similar to `"02.234"`. */
162- export function seconds2 ( timestamp : { readonly seconds : number } ) : string {
163- return String ( timestamp . seconds ) . replace ( / ^ \d + / u, s => s . padStart ( 2 , "0" ) ) ;
164- }
147+ export const seconds2 = formatTime . seconds2 ;
165148
166149/** Rounds the seconds portion of the specified {@link Timestamp} down and
167150 * formats the result as a numeric string. */
168- export function floorSeconds ( timestamp : { readonly seconds : number } ) : string {
169- return String ( Math . floor ( timestamp . seconds ) ) ;
170- }
151+ export const floorSeconds = formatTime . floorSeconds ;
171152
172153/** Rounds the seconds portion of the specified {@link Timestamp} down and
173154 * formats the result as a 2-digit numeric string. */
174- export function floorSeconds2 ( timestamp : { readonly seconds : number } ) : string {
175- return String ( Math . floor ( timestamp . seconds ) ) . padStart ( 2 , "0" ) ;
176- }
155+ export const floorSeconds2 = formatTime . floorSeconds2 ;
177156
178157/** Rounds the seconds portion of the specified {@link Timestamp} down to the
179158 * next lower millisecond, and formats the result as a 2.3-digit string. */
180- export function secondsMs ( timestamp : { readonly seconds : number } ) : string {
181- const s = String ( Math . floor ( timestamp . seconds * 1000 ) ) . padStart ( 5 , "0" ) ;
182- return `${ s . substr ( 0 , 2 ) } .${ s . substr ( 2 ) } ` ;
183- }
159+ export const secondsMs = formatTime . secondsMs ;
184160
185161/** Formats the specified {@link Timestamp} as IS0 8601 extended, rounded down
186162 * to the next lower second e.g. `"2021-05-01T11:57:23Z"`. */
0 commit comments