MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / formatResetTime

Function formatResetTime

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

Source from the content-addressed store, hash-verified

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