github.com/cyverse/go-irodsclient@v0.13.2/irods/util/irods_time.go (about)

     1  package util
     2  
     3  import (
     4  	"strconv"
     5  	"time"
     6  
     7  	"golang.org/x/xerrors"
     8  )
     9  
    10  // GetIRODSDateTime returns time struct from string IRODS time
    11  func GetIRODSDateTime(timestring string) (time.Time, error) {
    12  	i64, err := strconv.ParseInt(timestring, 10, 64)
    13  	if err != nil {
    14  		return time.Time{}, xerrors.Errorf("cannot parse IRODS time string '%s'", timestring)
    15  	}
    16  
    17  	if i64 <= 0 {
    18  		return time.Time{}, nil
    19  	}
    20  
    21  	return time.Unix(i64, 0), nil
    22  }
    23  
    24  // GetIRODSDateTimeStringForTicket returns IRODS time string from time struct
    25  func GetIRODSDateTimeStringForTicket(t time.Time) string {
    26  	if t.IsZero() {
    27  		return "0"
    28  	}
    29  
    30  	return t.UTC().Format("2006-01-02.15:04:05")
    31  }