14 lines
431 B
Go
14 lines
431 B
Go
|
package timeext
|
||
|
|
||
|
import "time"
|
||
|
|
||
|
func YearDifference(t1 time.Time, t2 time.Time, tz *time.Location) float64 {
|
||
|
|
||
|
yDelta := float64(t1.Year() - t2.Year())
|
||
|
|
||
|
processT1 := float64(t1.Sub(TimeToYearStart(t1, tz))) / float64(TimeToYearEnd(t1, tz).Sub(TimeToYearStart(t1, tz)))
|
||
|
processT2 := float64(t2.Sub(TimeToYearStart(t2, tz))) / float64(TimeToYearEnd(t2, tz).Sub(TimeToYearStart(t2, tz)))
|
||
|
|
||
|
return yDelta + (processT1 - processT2)
|
||
|
}
|