本文整理汇总了Golang中Time.Time函数的典型用法代码示例。如果您正苦于以下问题:Golang Time函数的具体用法?Golang Time怎么用?Golang Time使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Time函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ImportNodes
// read nodes.json compatible data into database
func (db *NodeDB) ImportNodes(r io.Reader, persistent bool) error {
nodes, err := readNodesJSON(r)
if err != nil {
return err
}
if nodes.Version != 1 {
return ErrUnknownVersion
}
for _, node := range nodes.Nodes {
var addr alfred.HardwareAddr
if err := addr.Parse(node.NodeInfo.NodeID); err != nil {
log.Printf("Import: error parsing NodeID %s: %v, skipping", node.NodeInfo.NodeID, err)
continue
}
n := &NodeInfo{NodeInfo: gluon.NodeInfo{Source: addr, Data: &node.NodeInfo}}
m := store.NewMeta(n)
m.Updated = time.Time(node.LastSeen).Local()
m.Created = time.Time(node.FirstSeen).Local()
if !persistent {
m.InvalidateIn(db.validTimeGluon)
}
err := db.Main.Batch(func(tx *bolt.Tx) error {
return db.Main.UpdateMeta(tx, store.NewMeta(&NodeInfo{}), m)
})
if err != nil {
log.Printf("Import: error on node %v", node.NodeInfo.NodeID)
}
}
return err
}
示例2: get_latest
/*
Use the arch, software and version to find the latest
*/
func get_latest(arch string, software string, version string) (dropbox.Entry, bool) {
target_path := get_target_path(arch, version)
s := []string{}
s = append(s, software)
s = append(s, "-")
search := strings.Join(s, "")
mTime := time.Time(dropbox.DBTime{})
var latest_file dropbox.Entry
files := get_files(cache_instance, db, target_path)
for _, file := range files {
if strings.Contains(file.Path, search) {
if time.Time(file.Modified).After(mTime) {
mTime = time.Time(file.Modified)
latest_file = file
}
}
}
if latest_file.Path == "" {
return latest_file, false
} else {
return latest_file, true
}
}
示例3: ToLogdata
func (r *RRD) ToLogdata(out chan<- map[string]Logitem) error {
names := make([]string, 0, 5)
for _, ds := range r.DS {
if ds.Type != "GAUGE" {
return errors.New("unknown dataset type")
}
names = append(names, string(ds.Name))
}
for _, rra := range r.RRA {
step := time.Duration(rra.PDPPerRow) * time.Duration(r.Step)
last_item := time.Time(r.LastUpdate).Round(step)
if time.Time(r.LastUpdate).Before(last_item) {
// correction for round-up behaviour
last_item = last_item.Add(-step)
}
first_item := last_item.Add(-step * time.Duration(len(rra.Database.Row)-1))
for row, items := range rra.Database.Row {
data := make(map[string]Logitem)
for nr, v := range items.V {
data[names[nr]] = Logitem{Timestamp: first_item.Add(step * time.Duration(row)), Value: v}
}
out <- data
}
}
return nil
}
示例4: computeHistogramInterval
// Returns the Timerange interval as both float32 and string that can be passed
// to the Elasticseach date_histogram field. For example, 613.234s is a valid
// interval. The interval is computed in such a way so that there will be
// approximately the given number of points in the histogram.
func computeHistogramInterval(tr *datetime.Timerange, points int) (float32, string) {
// the bucket interval in seconds (can be a float)
total_interval := time.Time(tr.To).Sub(time.Time(tr.From))
interval_secs := float32(int64(total_interval)/int64(points)/int64(1e6)) / 1000
return interval_secs, fmt.Sprintf("%.3fs", interval_secs)
}
示例5: testCreatedJsonTime
func testCreatedJsonTime(engine *xorm.Engine, t *testing.T) {
di5 := new(MyJsonTime)
err := engine.Sync2(di5)
if err != nil {
t.Fatal(err)
}
ci5 := &MyJsonTime{}
_, err = engine.Insert(ci5)
if err != nil {
t.Fatal(err)
}
has, err := engine.Desc("(id)").Get(di5)
if err != nil {
t.Fatal(err)
}
if !has {
t.Fatal(xorm.ErrNotExist)
}
if time.Time(ci5.Created).Unix() != time.Time(di5.Created).Unix() {
t.Fatal("should equal:", time.Time(ci5.Created).Unix(), time.Time(di5.Created).Unix())
}
fmt.Println("ci5:", ci5, "di5:", di5)
var dis = make([]MyJsonTime, 0)
err = engine.Find(&dis)
if err != nil {
t.Fatal(err)
}
}
示例6: String
func (task *Task) String() string {
var fields = []string{
"Type: Task",
task.Object.String(),
"Closed: " + strconv.FormatBool(task.Closed),
"Planned start: " + time.Time(task.PlannedStart).String(),
"Planned end: " + time.Time(task.PlannedEnd).String(),
"Planned duration: " + time.Duration(task.PlannedDuration).String(),
"Estimated start: " + time.Time(task.EstimatedStart).String(),
"Estimated end: " + time.Time(task.EstimatedEnd).String(),
"Estimated duration: " + time.Duration(task.EstimatedDuration).String(),
"Planned effort: " + time.Duration(task.PlannedEffort).String(),
"Estimated effort: " + time.Duration(task.EstimatedEffort).String(),
"Current effort: " + time.Duration(task.CurrentEffort).String(),
"Estimated progress: " + strconv.FormatFloat(float64(task.EstimatedProgress), 'f', 2, 64),
"Planned progress: " + strconv.FormatFloat(float64(task.PlannedProgress), 'f', 2, 64),
}
var dependencies = []string{"Tasks:"}
var resources = []string{"Assigned resources:"}
var efforts = []string{"Efforts:"}
for _, value := range task.OutgoingDependencies {
dependencies = append(dependencies, "\t"+value.String())
}
for _, value := range task.Resources {
resources = append(resources, "\t"+value.String())
}
for _, value := range task.Efforts {
efforts = append(efforts, "\t"+value.String())
}
return strings.Join(append(append(append(fields, dependencies...), resources...), efforts...), "\n")
}
示例7: Equal
func (s Time) Equal(v Value) bool {
t, ok := v.(Time)
if !ok {
return false
}
return time.Time(s).Equal(time.Time(t))
}
示例8: MarshalText
// MarshalText implements the encoding.TextMarshaler interface
func (t JSONTime) MarshalText() ([]byte, error) {
if time.Time(t).IsZero() || time.Time(t).Unix() == 0 {
return []byte{}, nil
}
stamp := time.Time(t).UTC().Format(time.RFC3339Nano)
return []byte(stamp), nil
}
示例9: ConvertToActivity
func ConvertToActivity(rkActivity *runkeeper.FitnessActivity) *dm.Activity {
returnActivity := dm.CreateActivity()
if rkActivity.Type == "Other" {
returnActivity.Type = "Activity"
} else {
returnActivity.Type = rkActivity.Type
}
//RK time is 'Local'
correctedTime := time.Time(rkActivity.StartTime).Add(time.Duration(rkActivity.UtcOffset) * time.Hour)
log.Printf("RK Local date: %s, start date: %s, unix: %d, offset: %d", time.Time(rkActivity.StartTime), correctedTime, time.Time(rkActivity.StartTime).Unix(), rkActivity.UtcOffset)
returnActivity.StartTime = int(time.Time(correctedTime).Unix())
returnActivity.UtcOffSet = rkActivity.UtcOffset
returnActivity.Duration = int(rkActivity.Duration)
returnActivity.Name = rkActivity.Notes
returnActivity.Notes = "" //rkActivity.Comment //hmm dunno
returnActivity.Private = false
returnActivity.Stationary = rkActivity.HasMap
returnActivity.AverageHeartRate = 0 //rkActivity.AverageHeartRate
returnActivity.Calories = rkActivity.TotalCalories
returnActivity.Distance = rkActivity.TotalDistance
returnActivity.GPS = convertFromPath(rkActivity.Path)
returnActivity.HeartRate = convertFromHR(rkActivity.HeartRate)
//log.Printf("INPUT: %s, OUTPUT: %s", rkActivity, returnActivity)
return returnActivity
}
示例10: fetchLatestTarVersions
// fetchLatestTarVersions reads the atlassian download feed and fetches the
// latest tar.gz entry for each version.
func fetchLatestTarVersions(url string) (versions map[string]Package, err error) {
resp, err := http.Get(url)
if err != nil {
return nil, err
}
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
start := bytes.Index(data, []byte("("))
end := bytes.LastIndex(data, []byte(")"))
if !(end > start && start > -1) {
return nil, errors.New("error in jsonp content")
}
var archives []Package
err = json.Unmarshal(data[start+1:end], &archives)
if err != nil {
return nil, err
}
versions = map[string]Package{}
for _, archive := range archives {
filename := path.Base(archive.ZipURL)
if !strings.Contains(filename, ".tar.gz") {
continue
}
majmin := archive.Version.MajorMinor()
v, ok := versions[majmin]
if !ok || time.Time(archive.Released).After(time.Time(v.Released)) {
versions[majmin] = archive
}
}
return versions, nil
}
示例11: UnmarshalJSON
func (r *CopyHeader) UnmarshalJSON(b []byte) error {
type tmp CopyHeader
var s struct {
tmp
ContentLength string `json:"Content-Length"`
CopiedFromLastModified gophercloud.JSONRFC1123 `json:"X-Copied-From-Last-Modified"`
Date gophercloud.JSONRFC1123 `json:"Date"`
LastModified gophercloud.JSONRFC1123 `json:"Last-Modified"`
}
err := json.Unmarshal(b, &s)
if err != nil {
return err
}
*r = CopyHeader(s.tmp)
switch s.ContentLength {
case "":
r.ContentLength = 0
default:
r.ContentLength, err = strconv.ParseInt(s.ContentLength, 10, 64)
if err != nil {
return err
}
}
r.Date = time.Time(s.Date)
r.CopiedFromLastModified = time.Time(s.CopiedFromLastModified)
r.LastModified = time.Time(s.LastModified)
return nil
}
示例12: PermanodeTimeLocked
// PermanodeTimeLocked returns the time of the content in permanode.
func (c *Corpus) PermanodeTimeLocked(pn blob.Ref) (t time.Time, ok bool) {
// TODO(bradfitz): keep this time property cached on the permanode / files
// TODO(bradfitz): finish implmenting all these
// Priorities:
// -- Permanode explicit "camliTime" property
// -- EXIF GPS time
// -- Exif camera time
// -- File time
// -- File modtime
// -- camliContent claim set time
ccRef, ccTime, ok := c.pnCamliContentLocked(pn)
if !ok {
return
}
fi, ok := c.files[ccRef]
if ok {
if fi.Time != nil {
return time.Time(*fi.Time), true
}
if fi.ModTime != nil {
return time.Time(*fi.ModTime), true
}
}
return ccTime, true
}
示例13: UpdateCommitInfo
// UpdateCommitInfo finds all the new commits since the last time we ran and
// adds them to the tiles, creating new tiles if necessary.
func (i *Ingester) UpdateCommitInfo(pull bool) error {
glog.Infof("Ingest %s: Starting UpdateCommitInfo", i.datasetName)
if err := i.git.Update(pull, false); err != nil {
return fmt.Errorf("Ingest %s: Failed git pull for during UpdateCommitInfo: %s", i.datasetName, err)
}
// Compute Git CL number for each Git hash.
allHashes := i.git.From(time.Time(BEGINNING_OF_TIME))
hashToNumber := map[string]int{}
for i, h := range allHashes {
hashToNumber[h] = i
}
i.hashToNumber = hashToNumber
// Find the time of the last Commit seen.
ts := time.Time(BEGINNING_OF_TIME)
lastTile, err := i.tileStore.Get(0, -1)
if err == nil && lastTile != nil {
ts = i.lastCommitTimeInTile(lastTile)
} else {
// Boundary condition; just started making Tiles and none exist.
newTile := tiling.NewTile()
newTile.Scale = 0
newTile.TileIndex = 0
if err := i.tileStore.Put(0, 0, newTile); err != nil {
return fmt.Errorf("Ingest %s: UpdateCommitInfo: Failed to write new tile: %s", i.datasetName, err)
}
}
glog.Infof("Ingest %s: UpdateCommitInfo: Last commit timestamp: %s", i.datasetName, ts)
// Find all the Git hashes that are new to us.
newHashes := i.git.From(ts)
glog.Infof("Ingest %s: len(newHashes): from %d", i.datasetName, len(newHashes))
// Add Commit info to the Tiles for each new hash.
tt := NewTileTracker(i.tileStore, i.hashToNumber)
for _, hash := range newHashes {
if err := tt.Move(hash); err != nil {
glog.Errorf("UpdateCommitInfo Move(%s) failed with: %s", hash, err)
continue
}
details, err := i.git.Details(hash, true)
if err != nil {
glog.Errorf("Failed to get details for hash: %s: %s", hash, err)
continue
}
tt.Tile().Commits[tt.Offset(hash)] = &tiling.Commit{
CommitTime: details.Timestamp.Unix(),
Hash: hash,
Author: details.Author,
}
}
glog.Infof("Ingest %s: Starting to flush tile.", i.datasetName)
tt.Flush()
glog.Infof("Ingest %s: Finished UpdateCommitInfo", i.datasetName)
return nil
}
示例14: String
func (dates *ProjectSummaryDates) String() string {
var fields = []string{
time.Time(dates.Planned).String() + " (Planned)",
time.Time(dates.Estimated).String() + " (Estimated)",
}
return strings.Join(fields, " ")
}
示例15: nextAfter
func (self Date) nextAfter(t time.Time) (time.Time, error) {
if t.Before(time.Time(self)) {
return time.Time(self), nil
}
var zeroTime time.Time
return zeroTime, fmt.Errorf("no more occurrences after %s", t)
}