@@ -97,6 +97,72 @@ func TestMonthlyPaymentSchedule(t *testing.T) {
9797 assert .NotEqual (t , math .LegacyOneDec (), s .EffectivePeriodProgress (ctx .WithBlockTime (time .Date (2000 , time .Month (startMonth ), daysInCurrentMonth , 23 , 59 , 59 , 0 , time .UTC ))))
9898 assert .Equal (t , math .LegacyOneDec (), s .EffectivePeriodProgress (ctx .WithBlockTime (time .Date (2000 , time .Month (startMonth )+ 1 , 1 , 0 , 0 , 0 , 0 , time .UTC ))))
9999 }
100+
101+ for _ , loc := range []* time.Location {
102+ time .FixedZone ("BakerIsland" , - 12 * 3600 ),
103+ time .FixedZone ("AzoresIslands" , - 1 * 3600 ),
104+ time .UTC ,
105+ time .FixedZone ("Berlin" , 1 * 3600 ),
106+ time .FixedZone ("LineIslands" , 14 * 3600 ),
107+ } {
108+ t .Run ("TimezoneOperations" + loc .String (), func (t * testing.T ) {
109+ time .Local = loc // set the timezone for the test
110+
111+ t .Run ("BeginningOfMonth" , func (t * testing.T ) {
112+ // timestamp is in the beginning of the month: 2000-01-01 00:00:01
113+ s = & revenuetypes.MonthlyPaymentSchedule {
114+ CurrentMonthStartBlockTs : uint64 (time .Date (2000 , time .January , 1 , 0 , 0 , 0 , 0 , time .UTC ).Unix ()), //nolint:gosec
115+ }
116+
117+ // check that the current month is January regardless of the timezone
118+ assert .Equal (t , time .January , s .CurrentMonth ())
119+
120+ // make sure period end edge cases result in the same regardless of the timezone
121+ assert .Equal (t , false , s .PeriodEnded (ctx .WithBlockTime (time .Date (2000 , time .January , 1 , 0 , 0 , 0 , 0 , time .UTC ))))
122+ assert .Equal (t , false , s .PeriodEnded (ctx .WithBlockTime (time .Date (2000 , time .January , 31 , 23 , 59 , 59 , 0 , time .UTC ))))
123+ assert .Equal (t , true , s .PeriodEnded (ctx .WithBlockTime (time .Date (2000 , time .February , 1 , 0 , 0 , 1 , 0 , time .UTC ))))
124+
125+ // make sure effective period progress edge cases result in the same regardless of the timezone
126+ assert .Equal (t , math .LegacyZeroDec (), s .EffectivePeriodProgress (ctx .WithBlockTime (time .Date (2000 , time .January , 1 , 0 , 0 , 0 , 0 , time .UTC ))))
127+ assert .Equal (t , math .LegacyNewDecWithPrec (5 , 1 ), s .EffectivePeriodProgress (ctx .WithBlockTime (time .Date (2000 , time .January , 16 , 12 , 0 , 0 , 0 , time .UTC ))))
128+ assert .Equal (t , math .LegacyNewDecWithPrec (1344086021505376 , 18 ), s .EffectivePeriodProgress (ctx .WithBlockTime (time .Date (2000 , time .January , 1 , 1 , 0 , 0 , 0 , time .UTC ))))
129+ assert .Equal (t , math .LegacyNewDecWithPrec (999977598566308244 , 18 ), s .EffectivePeriodProgress (ctx .WithBlockTime (time .Date (2000 , time .January , 31 , 23 , 59 , 0 , 0 , time .UTC ))))
130+ assert .Equal (t , math .LegacyOneDec (), s .EffectivePeriodProgress (ctx .WithBlockTime (time .Date (2000 , time .February , 1 , 0 , 0 , 0 , 0 , time .UTC ))))
131+
132+ // make sure the next period start timestamp and month are the same regardless of the timezone
133+ nextPeriodStartDate := time .Date (2000 , time .February , 1 , 0 , 0 , 0 , 0 , time .UTC )
134+ s .StartNewPeriod (ctx .WithBlockTime (nextPeriodStartDate ))
135+ assert .Equal (t , time .February , s .CurrentMonth ())
136+ assert .Equal (t , uint64 (nextPeriodStartDate .Unix ()), s .CurrentMonthStartBlockTs ) //nolint:gosec
137+ })
138+
139+ t .Run ("EndOfMonth" , func (t * testing.T ) {
140+ // timestamp is in the end of the month: 2000-01-31 23:59:00
141+ s = & revenuetypes.MonthlyPaymentSchedule {
142+ CurrentMonthStartBlockTs : uint64 (time .Date (2000 , time .January , 31 , 23 , 59 , 0 , 0 , time .UTC ).Unix ()), //nolint:gosec
143+ }
144+
145+ // check that the current month is January regardless of the timezone
146+ assert .Equal (t , time .January , s .CurrentMonth ())
147+
148+ // make sure period end edge cases result in the same regardless of the timezone
149+ assert .Equal (t , false , s .PeriodEnded (ctx .WithBlockTime (time .Date (2000 , time .January , 31 , 23 , 59 , 0 , 0 , time .UTC ))))
150+ assert .Equal (t , false , s .PeriodEnded (ctx .WithBlockTime (time .Date (2000 , time .January , 31 , 23 , 59 , 59 , 0 , time .UTC ))))
151+ assert .Equal (t , true , s .PeriodEnded (ctx .WithBlockTime (time .Date (2000 , time .February , 1 , 0 , 0 , 1 , 0 , time .UTC ))))
152+
153+ // make sure effective period progress edge cases result in the same regardless of the timezone
154+ assert .Equal (t , math .LegacyZeroDec (), s .EffectivePeriodProgress (ctx .WithBlockTime (time .Date (2000 , time .January , 31 , 23 , 59 , 0 , 0 , time .UTC ))))
155+ assert .Equal (t , math .LegacyNewDecWithPrec (22028076463560 , 18 ), s .EffectivePeriodProgress (ctx .WithBlockTime (time .Date (2000 , time .January , 31 , 23 , 59 , 59 , 0 , time .UTC ))))
156+ assert .Equal (t , math .LegacyNewDecWithPrec (22401433691756 , 18 ), s .EffectivePeriodProgress (ctx .WithBlockTime (time .Date (2000 , time .February , 1 , 0 , 0 , 0 , 0 , time .UTC ))))
157+
158+ // make sure the next period start timestamp and month are the same regardless of the timezone
159+ nextPeriodStartDate := time .Date (2000 , time .February , 1 , 0 , 0 , 0 , 0 , time .UTC )
160+ s .StartNewPeriod (ctx .WithBlockTime (nextPeriodStartDate ))
161+ assert .Equal (t , time .February , s .CurrentMonth ())
162+ assert .Equal (t , uint64 (nextPeriodStartDate .Unix ()), s .CurrentMonthStartBlockTs ) //nolint:gosec
163+ })
164+ })
165+ }
100166}
101167
102168func TestBlockBasedPaymentSchedule (t * testing.T ) {
0 commit comments