Esempio n. 1
0
func timeSince(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
	errMsg := &pongo2.Error{
		Sender:   "filter:timeuntil/timesince",
		ErrorMsg: "time-value is not a time.Time string.",
	}

	dateStr, ok := in.Interface().(string)
	if !ok {
		return nil, errMsg
	}

	basetime, err := time.Parse(time.RFC3339, dateStr)
	if err != nil {
		return nil, errMsg
	}

	return pongo2.AsValue(util.FormatTime(basetime)), nil
}
Esempio n. 2
0
func (s *Server) FetchFeed(c *gin.Context, req proto.Message) (profile *pb.Profile, feed *pb.Feed, err error) {
	ctx, cancel := DefaultTimeoutContext()
	defer cancel()

	var format = false

	switch req.(type) {
	case *pb.FeedRequest:
		feed, err = s.client.FetchFeed(ctx, req.(*pb.FeedRequest))
		format = true
	case *pb.EntryRequest:
		feed, err = s.client.FetchEntry(ctx, req.(*pb.EntryRequest))
	}
	if err != nil {
		return
	}
	profile, err = s.CurrentUser(c)
	if err != nil {
		return
	}
	graph, err := s.CurrentGraph(c)
	if err != nil {
		return
	}
	var basetime time.Time
	for _, e := range feed.Entries {
		e.RebuildCommand(profile, graph)
		basetime, _ = time.Parse(time.RFC3339, e.Date)
		e.Date = util.FormatTime(basetime)

		if format {
			e.FormatComments(int32(0))
			e.FormatLikes(int32(0))
		}
		e.RebuildCommentsCommand(profile, graph)
	}
	return
}