You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

timestampnano.go 774B

12345678910111213141516171819202122232425262728
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package timeutil
  4. import (
  5. "time"
  6. "code.gitea.io/gitea/modules/setting"
  7. )
  8. // TimeStampNano is for nano time in database, do not use it unless there is a real requirement.
  9. type TimeStampNano int64
  10. // TimeStampNanoNow returns now nano int64
  11. func TimeStampNanoNow() TimeStampNano {
  12. return TimeStampNano(time.Now().UnixNano())
  13. }
  14. // AsTime convert timestamp as time.Time in Local locale
  15. func (tsn TimeStampNano) AsTime() (tm time.Time) {
  16. return tsn.AsTimeInLocation(setting.DefaultUILocation)
  17. }
  18. // AsTimeInLocation convert timestamp as time.Time in Local locale
  19. func (tsn TimeStampNano) AsTimeInLocation(loc *time.Location) time.Time {
  20. return time.Unix(0, int64(tsn)).In(loc)
  21. }