MCPcopy Create free account
hub / github.com/arctic-cli/interface / getTimeFilter

Function getTimeFilter

packages/arctic/src/provider/usage.ts:706–739  ·  view source on GitHub ↗
(period: TimePeriod, now: number)

Source from the content-addressed store, hash-verified

704 }
705
706 function getTimeFilter(period: TimePeriod, now: number): (timestamp: number) => boolean {
707 switch (period) {
708 case "session":
709 return () => true // No time filter for session mode
710
711 case "daily": {
712 const startOfDay = new Date(now)
713 startOfDay.setHours(0, 0, 0, 0)
714 return (timestamp: number) => timestamp >= startOfDay.getTime()
715 }
716
717 case "weekly": {
718 const startOfWeek = new Date(now)
719 // Get current day (0 = Sunday, 1 = Monday, etc.)
720 const currentDay = startOfWeek.getDay()
721 // Calculate days to subtract to get to Monday
722 // If Sunday (0), go back 6 days. Otherwise go back (currentDay - 1) days
723 const daysToMonday = currentDay === 0 ? 6 : currentDay - 1
724 startOfWeek.setDate(startOfWeek.getDate() - daysToMonday)
725 startOfWeek.setHours(0, 0, 0, 0)
726 return (timestamp: number) => timestamp >= startOfWeek.getTime()
727 }
728
729 case "monthly": {
730 const startOfMonth = new Date(now)
731 startOfMonth.setDate(1)
732 startOfMonth.setHours(0, 0, 0, 0)
733 return (timestamp: number) => timestamp >= startOfMonth.getTime()
734 }
735
736 default:
737 return () => true
738 }
739 }
740
741 async function fetchCodexUsage(input: {
742 provider: Provider.Info

Callers 1

fetchSessionUsageFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected