@@ -41,7 +41,9 @@ export default function UsageBasedBillingConfig({ attributionId }: Props) {
41
41
const [ billingError , setBillingError ] = useState < string | undefined > ( ) ;
42
42
43
43
const localStorageKey = `pendingStripeSubscriptionFor${ attributionId } ` ;
44
- const now = new Date ( ) ;
44
+ const billingPeriodFrom = new Date ( new Date ( ) . toISOString ( ) . slice ( 0 , 7 ) + "-01" ) ; // First day of this month: YYYY-MM-01T00:00:00.000Z
45
+ const billingPeriodTo = new Date ( billingPeriodFrom . getUTCFullYear ( ) , billingPeriodFrom . getMonth ( ) + 1 ) ; // First day of next month
46
+ billingPeriodTo . setMilliseconds ( billingPeriodTo . getMilliseconds ( ) - 1 ) ; // Last millisecond of this month
45
47
46
48
useEffect ( ( ) => {
47
49
if ( ! attributionId ) {
@@ -161,7 +163,7 @@ export default function UsageBasedBillingConfig({ attributionId }: Props) {
161
163
const response = await getGitpodService ( ) . server . listUsage ( {
162
164
attributionId,
163
165
order : Ordering . ORDERING_DESCENDING ,
164
- from : new Date ( now . toISOString ( ) . slice ( 0 , 7 ) + "-01" ) . getTime ( ) ,
166
+ from : billingPeriodFrom . getTime ( ) ,
165
167
to : Date . now ( ) ,
166
168
} ) ;
167
169
setCurrentUsage ( response . creditsUsed ) ;
@@ -225,7 +227,7 @@ export default function UsageBasedBillingConfig({ attributionId }: Props) {
225
227
</ button >
226
228
) }
227
229
</ span >
228
- { typeof currentUsage === "number" && typeof usageLimit === "number" && (
230
+ { typeof currentUsage === "number" && typeof usageLimit === "number" && usageLimit > 0 && (
229
231
< span className = "text-gray-400 dark:text-gray-500" >
230
232
{ Math . round ( ( 100 * currentUsage ) / usageLimit ) } % used
231
233
</ span >
@@ -238,7 +240,12 @@ export default function UsageBasedBillingConfig({ attributionId }: Props) {
238
240
< div className = "flex-grow" >
239
241
< div className = "uppercase text-sm text-gray-400 dark:text-gray-500" > Current Period</ div >
240
242
< div className = "text-sm font-medium text-gray-500 dark:text-gray-400" >
241
- { now . toLocaleString ( "default" , { month : "long" } ) } { now . getFullYear ( ) }
243
+ < span className = "font-semibold" >
244
+ { billingPeriodFrom . toLocaleString ( "default" , { month : "long" } ) } { " " }
245
+ { billingPeriodFrom . getFullYear ( ) }
246
+ </ span > { " " }
247
+ ({ billingPeriodFrom . toLocaleString ( "default" , { month : "short" , day : "numeric" } ) } -{ " " }
248
+ { billingPeriodTo . toLocaleString ( "default" , { month : "short" , day : "numeric" } ) } )
242
249
</ div >
243
250
</ div >
244
251
< div >
0 commit comments