github.com/dim13/unifi@v0.0.0-20230308161331-9b04946f5e93/timestamp.go (about)

     1  // Copyright (c) 2014 The unifi Authors. All rights reserved.
     2  // Use of this source code is governed by ISC-style license
     3  // that can be found in the LICENSE file.
     4  
     5  package unifi
     6  
     7  import (
     8  	"strconv"
     9  	"time"
    10  )
    11  
    12  type Timestamp time.Time
    13  
    14  func (t *Timestamp) UnmarshalJSON(b []byte) error {
    15  	res, err := strconv.ParseInt(string(b), 0, 32)
    16  	if err != nil {
    17  		return err
    18  	}
    19  	*t = Timestamp(time.Unix(res, 0))
    20  	return nil
    21  }
    22  
    23  func (t Timestamp) String() string {
    24  	return time.Time(t).String()
    25  }