github.com/wangyougui/gf/v2@v2.6.5/os/gtime/gtime_time_wrapper.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/wangyougui/gf.
     6  
     7  package gtime
     8  
     9  import (
    10  	"time"
    11  )
    12  
    13  // wrapper is a wrapper for stdlib struct time.Time.
    14  // It's used for overwriting some functions of time.Time, for example: String.
    15  type wrapper struct {
    16  	time.Time
    17  }
    18  
    19  // String overwrites the String function of time.Time.
    20  func (t wrapper) String() string {
    21  	if t.IsZero() {
    22  		return ""
    23  	}
    24  	if t.Year() == 0 {
    25  		// Only time.
    26  		return t.Format("15:04:05")
    27  	}
    28  	return t.Format("2006-01-02 15:04:05")
    29  }