github.com/blend/go-sdk@v1.20220411.3/timeutil/diff_hours.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package timeutil
     9  
    10  import "time"
    11  
    12  // DiffHours returns the difference in hours between two times.
    13  func DiffHours(t1, t2 time.Time) (hours int) {
    14  	t1n := t1.Unix()
    15  	t2n := t2.Unix()
    16  	var diff int64
    17  	if t1n > t2n {
    18  		diff = t1n - t2n
    19  	} else {
    20  		diff = t2n - t1n
    21  	}
    22  	return int(diff / (SecondsPerHour))
    23  }