本文整理汇总了Golang中Time.Time.Equal方法的典型用法代码示例。如果您正苦于以下问题:Golang Time.Equal方法的具体用法?Golang Time.Equal怎么用?Golang Time.Equal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Time.Time
的用法示例。
在下文中一共展示了Time.Equal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Login
func (fa *FakeAuth) Login(rietveldURL string, after time.Time) error {
fa.callLog = append(fa.callLog, "Login", rietveldURL)
if !after.Equal(fixedSignTime) {
return fmt.Errorf("FakeAuth: want fixedSignTime, got %v", after)
}
return nil
}
示例2: calculateMovingAverageTxDates
// calculateMovingAverageTxDates determines the buy and sell dates for a unit based on moving average crossovers
// it returns the buyDates and the sellDates
func calculateMovingAverageTxDates(fastAvgPeriod int, slowAvgPeriod int, firstAllowedBuyDate time.Time, pricesPtr *[]metric.Metric) (*[]time.Time, *[]time.Time) {
fastAvg := analyser.MovingAverage(fastAvgPeriod, pricesPtr)
slowAvg := analyser.MovingAverage(slowAvgPeriod, pricesPtr)
// Make the avgs start on the same date
fastAvg = fastAvg[slowAvgPeriod-fastAvgPeriod:]
// Work out the buy and sell dates
buy := make([]time.Time, 0)
sell := make([]time.Time, 0)
for i := 1; i < len(fastAvg); i++ {
if fastAvg[i].Value > slowAvg[i].Value &&
fastAvg[i-1].Value < slowAvg[i-1].Value &&
(firstAllowedBuyDate.Before(fastAvg[i].Time) || firstAllowedBuyDate.Equal(fastAvg[i].Time)) {
// Low to high crossover - buy
buy = append(buy, fastAvg[i].Time)
} else if fastAvg[i].Value < slowAvg[i].Value && fastAvg[i-1].Value > slowAvg[i-1].Value && len(buy) > 0 {
// High to low crossover - sell, can only sell if we've previously bought
sell = append(sell, fastAvg[i].Time)
}
}
return &buy, &sell
}
示例3: Begins
// Begins returns the timestamp of the beginning of this RRA assuming
// that that the argument "now" is within it. This will be a time
// approximately but not exactly the RRA length ago, because it is
// aligned on the RRA step boundary.
func (rra *RoundRobinArchive) Begins(now time.Time) time.Time {
rraStart := now.Add(rra.step * time.Duration(rra.size) * -1).Truncate(rra.step)
if now.Equal(now.Truncate(rra.step)) {
rraStart = rraStart.Add(rra.step)
}
return rraStart
}
示例4: TestTimeISO8601
func (s *RethinkSuite) TestTimeISO8601(c *test.C) {
var t1, t2 time.Time
t2, _ = time.Parse("2006-01-02T15:04:05-07:00", "1986-11-03T08:30:00-07:00")
err := ISO8601("1986-11-03T08:30:00-07:00").RunRow(sess).Scan(&t1)
c.Assert(err, test.IsNil)
c.Assert(t1.Equal(t2), test.Equals, true)
}
示例5: isKeyValidAt
// isKeyValidAt returns whether the account key is valid at 'when' time.
func (ak *AccountKey) isKeyValidAt(when time.Time) bool {
valid := when.After(ak.since) || when.Equal(ak.since)
if valid && !ak.until.IsZero() {
valid = when.Before(ak.until)
}
return valid
}
示例6: TestMock
func TestMock(t *testing.T) {
example := mockResult(1, "int", "str", "bool", "float", "time")
example.Next()
var num int64
var str string
var boolean bool
var float float64
var timestamp time.Time
example.Scanner.Scan(&num, &str, &boolean, &float, ×tamp)
if num != mockInt {
t.Errorf("Unequal mock int: have %d, want %d", num, mockInt)
}
if str != mockStr {
t.Errorf("Unequal mock str: have %s, want %s", str, mockStr)
}
if boolean != mockBool {
t.Errorf("Unequal mock bool: have %t, want %t", boolean, mockBool)
}
if float != mockFloat {
t.Errorf("Unequal mock float: have %f, want %f", float, mockFloat)
}
if !timestamp.Equal(mockTime) {
t.Errorf("Unequal mock time: have %v, want %v", timestamp, mockTime)
}
}
示例7: TestParse
func TestParse(t *testing.T) {
var (
s string
p, x time.Time
err error
)
// Local time
now := time.Now()
times := map[string]time.Time{
"5m": now.Add(time.Duration(time.Minute * 5)),
"-0h": now.Add(-time.Duration(time.Hour * 0)),
"-48h5m": now.Add(-time.Duration(time.Hour*48 + time.Minute*5)),
// UTC
"2013-04-10": time.Date(2013, 4, 10, 0, 0, 0, 0, time.UTC),
"April 4, 2013": time.Date(2013, 4, 4, 0, 0, 0, 0, time.UTC),
"Apr 04, 2013": time.Date(2013, 4, 4, 0, 0, 0, 0, time.UTC),
"47065363200000000": time.Date(1492, 6, 11, 0, 0, 0, 0, time.UTC),
"02-01-2006": time.Date(2006, 1, 2, 0, 0, 0, 0, time.UTC),
"02-01-2006 2:04 PM": time.Date(2006, 1, 2, 14, 4, 0, 0, time.UTC),
"02-01-2006 2:04 PM -0700": time.Date(2006, 1, 2, 21, 4, 0, 0, time.UTC),
"02-01-2006 2:04 PM -07:00": time.Date(2006, 1, 2, 21, 4, 0, 0, time.UTC),
"2 January 2006": time.Date(2006, 1, 2, 0, 0, 0, 0, time.UTC),
"2 January 2006 3:04 PM": time.Date(2006, 1, 2, 15, 4, 0, 0, time.UTC),
"2 January 2006 3:04 PM -0700": time.Date(2006, 1, 2, 22, 4, 0, 0, time.UTC),
"2 January 2006 3:04 PM -07:00": time.Date(2006, 1, 2, 22, 4, 0, 0, time.UTC),
"2006-01-02": time.Date(2006, 1, 2, 0, 0, 0, 0, time.UTC),
"2006-01-02 3:04 PM": time.Date(2006, 1, 2, 15, 4, 0, 0, time.UTC),
"2006-01-02 3:04 PM -0700": time.Date(2006, 1, 2, 22, 4, 0, 0, time.UTC),
"2006-01-02 3:04 PM -07:00": time.Date(2006, 1, 2, 22, 4, 0, 0, time.UTC),
"January 2, 2006": time.Date(2006, 1, 2, 0, 0, 0, 0, time.UTC),
"January 2, 2006 3:04 PM": time.Date(2006, 1, 2, 15, 4, 0, 0, time.UTC),
"January 2, 2006 3:04 PM -0700": time.Date(2006, 1, 2, 22, 4, 0, 0, time.UTC),
"January 2, 2006 3:04 PM -07:00": time.Date(2006, 1, 2, 22, 4, 0, 0, time.UTC),
"Jan 2, 2006": time.Date(2006, 1, 2, 0, 0, 0, 0, time.UTC),
"Jan 2, 2006, 3:04 PM": time.Date(2006, 1, 2, 15, 4, 0, 0, time.UTC),
"Jan 2, 2006 3:04 PM -0700": time.Date(2006, 1, 2, 22, 4, 0, 0, time.UTC),
"Jan 2, 2006 3:04 PM -07:00": time.Date(2006, 1, 2, 22, 4, 0, 0, time.UTC),
}
// Duration to truncate for comparison.
td := time.Second
for s, x = range times {
p, err = Parse(s)
if err != nil {
t.Errorf("time: failed to parse %s as time", s)
} else {
x = x.Truncate(td)
p = p.Truncate(td)
if !p.Equal(x) {
t.Errorf("time: expected %s, got %s", x, p)
}
}
}
}
示例8: isStartOfMonth
func isStartOfMonth(t time.Time) bool {
y := t.Year()
m := t.Month()
utcLoc, _ := time.LoadLocation("UTC")
startOfMonth := time.Date(y, m, 1, 0, 0, 0, 0, utcLoc)
return t.Equal(startOfMonth)
}
示例9: LoadPerf
func LoadPerf(fName string, since, until time.Time) ([]PerfLogEntry, error) {
fIn, err := os.Open(fName)
if err != nil {
return nil, err
}
defer fIn.Close()
dec := json.NewDecoder(fIn)
var result []PerfLogEntry
for {
var entry PerfLogEntry
err = dec.Decode(&entry)
if err != nil {
if strings.Contains(err.Error(), "EOF") {
break
} else {
return nil, fmt.Errorf("Decode error: %v", err)
}
} else {
if !since.Equal(time.Time{}) && since.After(entry.Timestamp) {
continue
}
if !until.Equal(time.Time{}) && until.Before(entry.Timestamp) {
continue
}
result = append(result, entry)
}
}
return result, nil
}
示例10: in
func in(date, start, end time.Time) bool {
if date.Equal(start) || date.Equal(end) {
return true
}
return date.After(start) && date.Before(end)
}
示例11: GetMtime
func (r *VirtualMtimeRepo) GetMtime(path string, diskMtime time.Time) time.Time {
data, exists := r.ns.Bytes(path)
if !exists {
// Absense of debug print is significant enough in itself here
return diskMtime
}
var mtime time.Time
if err := mtime.UnmarshalBinary(data[:len(data)/2]); err != nil {
panic(fmt.Sprintf("Can't unmarshal stored mtime at path %s: %v", path, err))
}
if mtime.Equal(diskMtime) {
if err := mtime.UnmarshalBinary(data[len(data)/2:]); err != nil {
panic(fmt.Sprintf("Can't unmarshal stored mtime at path %s: %v", path, err))
}
if debug {
l.Debugf("virtual mtime: return %v instead of %v for path: %s", mtime, diskMtime, path)
}
return mtime
}
if debug {
l.Debugf("virtual mtime: record exists, but mismatch inDisk: %v dbDisk: %v for path: %s", diskMtime, mtime, path)
}
return diskMtime
}
示例12: surroundingStep
// surroundingStep returns begin and end of a PDP which either
// includes or ends on a given time mark.
func surroundingStep(mark time.Time, step time.Duration) (time.Time, time.Time) {
begin := mark.Truncate(step)
if mark.Equal(begin) { // We are exactly at the end, need to move one step back.
begin = begin.Add(step * -1)
}
return begin, begin.Add(step)
}
示例13: ftime2Func
func ftime2Func(t time.Time) string {
if t == zeroTime || t.Equal(walker.NotYetCrawled) {
return ""
} else {
return t.Format(timeFormat)
}
}
示例14: assertExpectedTUFMetaInStore
func assertExpectedTUFMetaInStore(t *testing.T, s MetaStore, expected []StoredTUFMeta, current bool) {
for _, tufObj := range expected {
var prevTime *time.Time
if current {
cDate, tufdata, err := s.GetCurrent(tufObj.Gun, tufObj.Role)
require.NoError(t, err)
require.Equal(t, tufObj.Data, tufdata)
// the update date was sometime wthin the last minute
require.True(t, cDate.After(time.Now().Add(-1*time.Minute)))
require.True(t, cDate.Before(time.Now().Add(5*time.Second)))
prevTime = cDate
}
checksumBytes := sha256.Sum256(tufObj.Data)
checksum := hex.EncodeToString(checksumBytes[:])
cDate, tufdata, err := s.GetChecksum(tufObj.Gun, tufObj.Role, checksum)
require.NoError(t, err)
require.Equal(t, tufObj.Data, tufdata)
if current {
require.True(t, prevTime.Equal(*cDate), "%s should be equal to %s", prevTime, cDate)
} else {
// the update date was sometime wthin the last minute
require.True(t, cDate.After(time.Now().Add(-1*time.Minute)))
require.True(t, cDate.Before(time.Now().Add(5*time.Second)))
}
}
}
示例15: ValidAt
// ValidAt returns whether the system-user is valid at 'when' time.
func (su *SystemUser) ValidAt(when time.Time) bool {
valid := when.After(su.since) || when.Equal(su.since)
if valid {
valid = when.Before(su.until)
}
return valid
}