package protocol

import (
	
	
	

	
)
Names of time formats supported by the SDK
const (
	RFC822TimeFormatName  = "rfc822"
	ISO8601TimeFormatName = "iso8601"
	UnixTimeFormatName    = "unixTimestamp"
)
Time formats supported by the SDK Output time is intended to not contain decimals
RFC 7231#section-7.1.1.1 timetamp format. e.g Tue, 29 Apr 2014 18:30:38 GMT
	RFC822TimeFormat = "Mon, 2 Jan 2006 15:04:05 GMT"
This format is used for output time without seconds precision
	RFC822OutputTimeFormat = "Mon, 02 Jan 2006 15:04:05 GMT"
RFC3339 a subset of the ISO8601 timestamp format. e.g 2014-04-29T18:30:38Z
	ISO8601TimeFormat = "2006-01-02T15:04:05.999999999Z"
This format is used for output time with fractional second precision up to milliseconds
	ISO8601OutputTimeFormat = "2006-01-02T15:04:05.999999999Z"
)
IsKnownTimestampFormat returns if the timestamp format name is know to the SDK's protocols.
func ( string) bool {
	switch  {
	case RFC822TimeFormatName:
		fallthrough
	case ISO8601TimeFormatName:
		fallthrough
	case UnixTimeFormatName:
		return true
	default:
		return false
	}
}
FormatTime returns a string value of the time.
func ( string,  time.Time) string {
	 = .UTC().Truncate(time.Millisecond)

	switch  {
	case RFC822TimeFormatName:
		return .Format(RFC822OutputTimeFormat)
	case ISO8601TimeFormatName:
		return .Format(ISO8601OutputTimeFormat)
	case UnixTimeFormatName:
		 := .UnixNano() / int64(time.Millisecond)
		return strconv.FormatFloat(float64()/1e3, 'f', -1, 64)
	default:
		panic("unknown timestamp format name, " + )
	}
}
ParseTime attempts to parse the time given the format. Returns the time if it was able to be parsed, and fails otherwise.
func (,  string) (time.Time, error) {
	switch  {
	case RFC822TimeFormatName:
		return time.Parse(RFC822TimeFormat, )
	case ISO8601TimeFormatName:
		return time.Parse(ISO8601TimeFormat, )
	case UnixTimeFormatName:
		,  := strconv.ParseFloat(, 64)
		,  := math.Modf()
		 = sdkmath.Round(*1e3) / 1e3 //Rounds 0.1229999 to 0.123
		if  != nil {
			return time.Time{}, 
		}
		return time.Unix(int64(), int64(*(1e9))), nil
	default:
		panic("unknown timestamp format name, " + )
	}