MCPcopy Index your code
hub / github.com/codeaashu/claude-code / formatResetTime

Function formatResetTime

src/utils/format.ts:238–289  ·  view source on GitHub ↗
(
  timestampInSeconds: number | undefined,
  showTimezone: boolean = false,
  showTime: boolean = true,
)

Source from the content-addressed store, hash-verified

236}
237
238export function formatResetTime(
239 timestampInSeconds: number | undefined,
240 showTimezone: boolean = false,
241 showTime: boolean = true,
242): string | undefined {
243 if (!timestampInSeconds) return undefined
244
245 const date = new Date(timestampInSeconds * 1000)
246 const now = new Date()
247 const minutes = date.getMinutes()
248
249 // Calculate hours until reset
250 const hoursUntilReset = (date.getTime() - now.getTime()) / (1000 * 60 * 60)
251
252 // If reset is more than 24 hours away, show the date as well
253 if (hoursUntilReset > 24) {
254 // Show date and time for resets more than a day away
255 const dateOptions: Intl.DateTimeFormatOptions = {
256 month: 'short',
257 day: 'numeric',
258 hour: showTime ? 'numeric' : undefined,
259 minute: !showTime || minutes === 0 ? undefined : '2-digit',
260 hour12: showTime ? true : undefined,
261 }
262
263 // Add year if it's not the current year
264 if (date.getFullYear() !== now.getFullYear()) {
265 dateOptions.year = 'numeric'
266 }
267
268 const dateString = date.toLocaleString('en-US', dateOptions)
269
270 // Remove the space before AM/PM and make it lowercase
271 return (
272 dateString.replace(/ ([AP]M)/i, (_match, ampm) => ampm.toLowerCase()) +
273 (showTimezone ? ` (${getTimeZone()})` : '')
274 )
275 }
276
277 // For resets within 24 hours, show just the time (existing behavior)
278 const timeString = date.toLocaleTimeString('en-US', {
279 hour: 'numeric',
280 minute: minutes === 0 ? undefined : '2-digit',
281 hour12: true,
282 })
283
284 // Remove the space before AM/PM and make it lowercase, then add timezone
285 return (
286 timeString.replace(/ ([AP]M)/i, (_match, ampm) => ampm.toLowerCase()) +
287 (showTimezone ? ` (${getTimeZone()})` : '')
288 )
289}
290
291export function formatResetText(
292 resetsAt: string,

Callers 4

formatResetTextFunction · 0.85
getLimitReachedTextFunction · 0.85
getEarlyWarningTextFunction · 0.85
getUsingOverageTextFunction · 0.85

Calls 1

getTimeZoneFunction · 0.85

Tested by

no test coverage detected