@@ -165,42 +165,85 @@ func (d ISODuration) DivisibleBy(smaller ISODuration) (bool, error) {
165165 return true , nil
166166}
167167
168+ func (p ISODuration ) Mul (n int ) (ISODuration , error ) {
169+ nDecimal , err := decimal .NewFromInt64 (int64 (n ), 0 , 0 )
170+ if err != nil {
171+ return ISODuration {}, err
172+ }
173+
174+ per , err := p .Period .Mul (nDecimal )
175+ if err != nil {
176+ return ISODuration {}, err
177+ }
178+ return ISODuration {per }, nil
179+ }
180+
168181// convertPeriodToSeconds converts a period to total seconds using decimal precision
169182func convertPeriodToSeconds (p period.Period , daysInMonth int , hoursInDays int ) (decimal.Decimal , error ) {
170- zero := decimal .MustNew (0 , 0 )
183+ zero := decimal .Zero
184+
185+ yearsMul , err := decimal .New (int64 (daysInMonth * 12 * hoursInDays * 3600 ), 0 )
186+ if err != nil {
187+ return zero , err
188+ }
171189
172190 // Convert years to seconds: years * (daysInMonth * 12) * hoursInDays * 3600
173- years , err := p .YearsDecimal ().Mul (decimal .MustNew (int64 (daysInMonth * 12 * hoursInDays * 3600 ), 0 ))
191+ years , err := p .YearsDecimal ().Mul (yearsMul )
192+ if err != nil {
193+ return zero , err
194+ }
195+
196+ monthsMul , err := decimal .New (int64 (daysInMonth * hoursInDays * 3600 ), 0 )
174197 if err != nil {
175198 return zero , err
176199 }
177200
178201 // Convert months to seconds: months * daysInMonth * hoursInDays * 3600
179- months , err := p .MonthsDecimal ().Mul (decimal .MustNew (int64 (daysInMonth * hoursInDays * 3600 ), 0 ))
202+ months , err := p .MonthsDecimal ().Mul (monthsMul )
203+ if err != nil {
204+ return zero , err
205+ }
206+
207+ weeksMul , err := decimal .New (int64 (7 * hoursInDays * 3600 ), 0 )
180208 if err != nil {
181209 return zero , err
182210 }
183211
184212 // Convert weeks to seconds: weeks * 7 * hoursInDays * 3600
185- weeks , err := p .WeeksDecimal ().Mul (decimal . MustNew ( int64 ( 7 * hoursInDays * 3600 ), 0 ) )
213+ weeks , err := p .WeeksDecimal ().Mul (weeksMul )
186214 if err != nil {
187215 return zero , err
188216 }
189217
190218 // Convert days to seconds: days * hoursInDays * 3600
191- days , err := p .DaysDecimal ().Mul (decimal .MustNew (int64 (hoursInDays * 3600 ), 0 ))
219+ daysMul , err := decimal .New (int64 (hoursInDays * 3600 ), 0 )
220+ if err != nil {
221+ return zero , err
222+ }
223+
224+ days , err := p .DaysDecimal ().Mul (daysMul )
192225 if err != nil {
193226 return zero , err
194227 }
195228
196229 // Convert hours to seconds: hours * 3600
197- hours , err := p .HoursDecimal ().Mul (decimal .MustNew (3600 , 0 ))
230+ hoursMul , err := decimal .New (int64 (3600 ), 0 )
231+ if err != nil {
232+ return zero , err
233+ }
234+
235+ hours , err := p .HoursDecimal ().Mul (hoursMul )
198236 if err != nil {
199237 return zero , err
200238 }
201239
202240 // Convert minutes to seconds: minutes * 60
203- minutes , err := p .MinutesDecimal ().Mul (decimal .MustNew (60 , 0 ))
241+ minutesMul , err := decimal .New (int64 (60 ), 0 )
242+ if err != nil {
243+ return zero , err
244+ }
245+
246+ minutes , err := p .MinutesDecimal ().Mul (minutesMul )
204247 if err != nil {
205248 return zero , err
206249 }
0 commit comments