summaryrefslogtreecommitdiffstats
path: root/modules/timeutil/timestampnano.go
blob: 4a9f7955b98127268f21edda9a3f14bc967f2de8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Copyright 2017 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package timeutil

import (
	"time"

	"code.gitea.io/gitea/modules/setting"
)

// TimeStampNano is for nano time in database, do not use it unless there is a real requirement.
type TimeStampNano int64

// TimeStampNanoNow returns now nano int64
func TimeStampNanoNow() TimeStampNano {
	return TimeStampNano(time.Now().UnixNano())
}

// AsTime convert timestamp as time.Time in Local locale
func (tsn TimeStampNano) AsTime() (tm time.Time) {
	return tsn.AsTimeInLocation(setting.DefaultUILocation)
}

// AsTimeInLocation convert timestamp as time.Time in Local locale
func (tsn TimeStampNano) AsTimeInLocation(loc *time.Location) time.Time {
	return time.Unix(0, int64(tsn)).In(loc)
}