MCPcopy Index your code
hub / github.com/triggerdotdev/jsonhero-web / formatDateTime

Function formatDateTime

app/utilities/formatter.ts:106–144  ·  view source on GitHub ↗
(
  value: string,
  format?: JSONDateTimeFormat
)

Source from the content-addressed store, hash-verified

104}
105
106export function formatDateTime(
107 value: string,
108 format?: JSONDateTimeFormat
109): string {
110 if (!format) {
111 return value;
112 }
113
114 const temporal = inferTemporal(value, format);
115
116 if (!temporal) {
117 return value;
118 }
119
120 switch (format.parts) {
121 case "datetime":
122 return temporal.toLocaleString("en-US", {
123 year: "numeric",
124 month: "short",
125 day: "numeric",
126 hour: "numeric",
127 minute: "numeric",
128 second: "numeric",
129 timeZoneName: "short",
130 });
131 case "date":
132 return temporal.toLocaleString("en-US", {
133 year: "numeric",
134 month: "short",
135 day: "numeric",
136 });
137 case "time":
138 return temporal.toLocaleString("en-US", {
139 hour: "numeric",
140 minute: "numeric",
141 second: "numeric",
142 });
143 }
144}
145
146export function formatBytes(bytes: number, decimals = 2): string {
147 if (bytes === 0) return "0 Bytes";

Callers 1

formatStringFunction · 0.85

Calls 1

inferTemporalFunction · 0.90

Tested by

no test coverage detected