Skip to content

Commit df32c3b

Browse files
jankeromnesroboquat
authored andcommitted
[usage] Update formula: 1 credit = 6 minutes, rounded up
1 parent 5b133ad commit df32c3b

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

components/usage/pkg/stripe/stripe.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package stripe
77
import (
88
"encoding/json"
99
"fmt"
10+
"math"
1011
"os"
1112
"strings"
1213

@@ -111,6 +112,7 @@ func queriesForCustomersWithTeamIds(teamIds []string) []string {
111112
}
112113

113114
// workspaceSecondsToCredits converts seconds (of workspace usage) into Stripe credits.
115+
// (1 credit = 6 minutes, rounded up)
114116
func workspaceSecondsToCredits(seconds int64) int64 {
115-
return (seconds + 59) / 60
117+
return int64(math.Ceil(float64(seconds) / (60 * 6)))
116118
}

components/usage/pkg/stripe/stripe_test.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,25 @@ func TestWorkspaceSecondsToCreditsCalcuation(t *testing.T) {
105105
Seconds: 60,
106106
ExpectedCredits: 1,
107107
},
108-
{
109-
Name: "61 seconds",
110-
Seconds: 61,
111-
ExpectedCredits: 2,
112-
},
113108
{
114109
Name: "90 seconds",
115110
Seconds: 90,
111+
ExpectedCredits: 1,
112+
},
113+
{
114+
Name: "6 minutes",
115+
Seconds: 360,
116+
ExpectedCredits: 1,
117+
},
118+
{
119+
Name: "6 minutes and 1 second",
120+
Seconds: 361,
116121
ExpectedCredits: 2,
117122
},
118123
{
119124
Name: "1 hour",
120125
Seconds: 3600,
121-
ExpectedCredits: 60,
126+
ExpectedCredits: 10,
122127
},
123128
}
124129

0 commit comments

Comments
 (0)