Esempio n. 1
0
func (c *Context) Rule() (string, error) {
	p := url.Values{}
	time := c.runHistory.Start
	p.Add("alert", c.Alert.Name)
	p.Add("fromDate", time.Format("2006-01-02"))
	p.Add("fromTime", time.Format("15:04"))
	p.Add("template_group", c.Group.Tags())
	return c.schedule.Conf.MakeLink("/config", &p), nil
}
Esempio n. 2
0
func (c *Context) Rule() (string, error) {
	p := url.Values{}
	//There might be something better when we tie the notifications to evaluation time issue #395
	time := time.Now().UTC()
	p.Add("alert", c.Alert.Name)
	p.Add("fromDate", time.Format("2006-01-02"))
	p.Add("fromTime", time.Format("15:04"))
	p.Add("template_group", c.Group.Tags())
	return c.schedule.Conf.MakeLink("/config", &p), nil
}
Esempio n. 3
0
File: data.go Progetto: ngc224/colle
func (dm *DataManager) SetItem(i ItemRedis) {
	con := dm.Get()
	i.Id = dm.GetNewItemId()
	time := GetFeedDateTime(i.PubDate)
	itemkeyname := REDISKEY_FEED_ITEM_PREFIX + strconv.Itoa(i.Id)
	con.Send("MULTI")
	con.Send("SADD", REDISKEY_FEED_EXISTS, i.Link)
	con.Send("ZADD", REDISKEY_FEED_TIME, time.Format(GetDateTimeFormat()), itemkeyname)
	if len(i.Category) > 0 {
		con.Send("ZADD", REDISKEY_FEED_TIME_PREFIX+i.Category, time.Format(GetDateTimeFormat()), itemkeyname)
	}
	con.Send("HMSET", redis.Args{itemkeyname}.AddFlat(i)...)
	con.Send("EXPIREAT", itemkeyname, time.AddDate(0, 0, dm.UserConfig.Site.ItemExpire).Unix())
	con.Do("EXEC")
}
Esempio n. 4
0
func (h HsbcLine) standardDate() string {
	time, err := time.Parse("02/01/2006", h.Date)
	if err != nil {
		log.Fatal(err)
	}
	return time.Format("2006-01-02")
}
Esempio n. 5
0
func (t TdLine) TransactionDate() string {
	time, err := time.Parse("02/01/2006", t.Date)
	if err != nil {
		log.Fatal(err)
	}
	return time.Format("2006-01-02")
}
Esempio n. 6
0
func (t TdLine) SettlementDate() string {
	time, err := time.Parse("02/01/2006", t.SettlementDate_)
	if err != nil {
		log.Fatal(err)
	}
	return time.Format("2006-01-02")
}
Esempio n. 7
0
func TestFormatShortYear(t *testing.T) {
	years := []int{
		-100001, -100000, -99999,
		-10001, -10000, -9999,
		-1001, -1000, -999,
		-101, -100, -99,
		-11, -10, -9,
		-1, 0, 1,
		9, 10, 11,
		99, 100, 101,
		999, 1000, 1001,
		9999, 10000, 10001,
		99999, 100000, 100001,
	}

	for _, y := range years {
		time := Date(y, January, 1, 0, 0, 0, 0, UTC)
		result := time.Format("2006.01.02")
		var want string
		if y < 0 {
			// The 4 in %04d counts the - sign, so print -y instead
			// and introduce our own - sign.
			want = fmt.Sprintf("-%04d.%02d.%02d", -y, 1, 1)
		} else {
			want = fmt.Sprintf("%04d.%02d.%02d", y, 1, 1)
		}
		if result != want {
			t.Errorf("(jan 1 %d).Format(\"2006.01.02\") = %q, want %q", y, result, want)
		}
	}
}
Esempio n. 8
0
func convertToItems(channel *rss.Channel) ([]types.Item, error) {
	items := make([]types.Item, len(channel.Item))
	for i := 0; i < len(channel.Item); i++ {
		from := channel.Item[i]
		to := types.Item{}
		to.Id = from.GUID
		to.Title = from.Title
		to.Description = html.UnescapeString(from.Description)
		to.Content = from.Content
		time, err := from.PubDate.Parse()
		if err != nil {
			to.Published = string(from.PubDate)
		} else {
			to.Published = time.Format(types.DateFormat)
		}
		if from.Enclosure.URL != "" {
			to.Type = from.Enclosure.Type
			to.Url = from.Enclosure.URL
		} else {
			to.Type = "Link"
			to.Url = from.Link
		}
		items[i] = to
	}
	return items, nil
}
Esempio n. 9
0
// issue 12440.
func TestFormatSingleDigits(t *testing.T) {
	time := Date(2001, 2, 3, 4, 5, 6, 700000000, UTC)
	test := FormatTest{"single digit format", "3:4:5", "4:5:6"}
	result := time.Format(test.format)
	if result != test.result {
		t.Errorf("%s expected %q got %q", test.name, test.result, result)
	}
}
Esempio n. 10
0
func TestFormat(t *testing.T) {
	// The numeric time represents Thu Feb  4 21:00:57.012345600 PST 2010
	time := Unix(0, 1233810057012345600)
	for _, test := range formatTests {
		result := time.Format(test.format)
		if result != test.result {
			t.Errorf("%s expected %q got %q", test.name, test.result, result)
		}
	}
}
Esempio n. 11
0
File: time_test.go Progetto: ssrl/go
func TestFormat(t *testing.T) {
	// The numeric time represents Thu Feb  4 21:00:57 PST 2010
	time := SecondsToLocalTime(1233810057)
	for _, test := range formatTests {
		result := time.Format(test.format)
		if result != test.result {
			t.Errorf("%s expected %q got %q", test.name, test.result, result)
		}
	}
}
Esempio n. 12
0
// Check that a time without a Zone still produces a (numeric) time zone
// when formatted with MST as a requested zone.
func TestMissingZone(t *testing.T) {
	time, err := Parse(RubyDate, "Thu Feb 02 16:10:03 -0500 2006")
	if err != nil {
		t.Fatal("error parsing date:", err)
	}
	expect := "Thu Feb  2 16:10:03 -0500 2006" // -0500 not EST
	str := time.Format(UnixDate)               // uses MST as its time zone
	if str != expect {
		t.Errorf("got %s; expect %s", str, expect)
	}
}
Esempio n. 13
0
func main() {
	value := "04/19/1979" // my birthday
	parseFormat := "01/02/2006"

	// parse the string into a time object
	time, _ := time.Parse(parseFormat, value)

	printFormat := "02.01.2006"

	// and print it with the desired format
	fmt.Println(time.Format(printFormat))
}
Esempio n. 14
0
func main() {
	flag.Parse()

	srcDir, err := os.Open(*src)
	if os.IsNotExist(err) {
		log.Fatalf("Directory '%v' does not exist: %v", *src, err)
	}

	files, err := srcDir.Readdir(-1)
	if err != nil {
		log.Fatalf("Error occured on reading '%v': %v", *src, err)
	}

	for _, f := range files {
		var ext string
		switch {
		case strings.HasSuffix(f.Name(), ".mp3"):
			ext = ".mp3"
		case strings.HasSuffix(f.Name(), ".m4a"):
			ext = ".m4a"
		default:
			continue
		}

		index := strings.LastIndex(f.Name(), ".")
		base := f.Name()[0:index]
		oldpath := filepath.Join(*src, f.Name())

		// file base name should be "YYYYmmdd-NNN"
		matched, err := regexp.MatchString(`\d{8}\-\d{3,4}`, base)
		if err != nil || !matched {
			continue
		}

		elements := strings.Split(base, "-")
		dateStr := elements[0]
		numberStr := elements[1]

		time, err := time.Parse("20060102", dateStr)
		if err != nil {
			log.Printf("Error occured to read date '%v': %v", dateStr, err)
			continue
		}
		filename := time.Format("伊集院光 深夜の馬鹿力 2006年01月02日") + " 第" + numberStr + "回" + ext
		newpath := filepath.Join(*src, filename)
		if err := os.Rename(oldpath, newpath); err != nil {
			log.Printf("Error on renaming '%v' -> '%v'", oldpath, newpath)
		}
	}
}
Esempio n. 15
0
// Function responsible for converting an integer of milliseconds to a timestamp
func MStoTimecode(milliseconds int) string {
	// Creates a zeroed out time object that we will add our duration to
	zero := new(time.Time)

	// Parses the integer passed
	duration, err := time.ParseDuration(strconv.Itoa(milliseconds) + "ms")
	if err != nil {
		return "00:00:00.000"
	}

	// Adds the duration to the zero time
	time := zero.Add(duration)

	// Returns the timestamp representation of our duration
	return time.Format("15:04:05.000")
}
Esempio n. 16
0
// Backup this method returns the hole database file
func (s *Sensorserver) Backup(c *gin.Context) {

	// filename contains the date
	time := time.Now()
	contentDisposition := `attachment; filename="` + time.Format("2006-01-02_15:04") + `-sensorserver.db"`

	err := s.boltdb.View(func(tx *bolt.Tx) error {
		c.Header("Content-Disposition", contentDisposition)
		c.Header("Content-Length", strconv.Itoa(int(tx.Size())))
		_, err := tx.WriteTo(c.Writer)

		return err
	})
	if err != nil {

		c.String(http.StatusInternalServerError, err.Error())
	}

}
Esempio n. 17
0
File: main.go Progetto: irth/blag
// LoadPost loads post file specified by path argument, and returns BlagPost
// object with data loaded from that file.
func LoadPost(config Config, fpath string) BlagPost {
	file, err := os.Open(fpath)
	if err != nil {
		panic(err)
	}
	buf := bufio.NewReader(file)
	yamlMeta := ""
	for !strings.HasSuffix(yamlMeta, "\n\n") {
		var s string
		s, err = buf.ReadString('\n')
		yamlMeta += s
	}

	var meta BlagPostMeta
	yaml.Unmarshal([]byte(yamlMeta), &meta)

	if meta.Timestamp <= 0 {
		stat, err := file.Stat()
		if err != nil {
			panic(err)
		}
		meta.Timestamp = stat.ModTime().Unix()
	}

	time := time.Unix(meta.Timestamp, 0)
	meta.Time = time.Format(*config.DateFormat)

	if len(meta.Slug) == 0 {
		basename := filepath.Base(file.Name())
		meta.Slug = strings.TrimSuffix(basename, filepath.Ext(basename))
	}

	markdown, _ := ioutil.ReadAll(buf)
	markdown = []byte(strings.Trim(string(markdown), " \r\n"))
	html := string(blackfriday.MarkdownCommon(markdown))
	return BlagPost{
		meta,
		html,
	}
}
//encrypt Spotify tokens before they store on DB.
func (e *EncryptToken) EncryptAccessToken() (dbToken models.Token, err error) {
	//strings
	dbToken.Access = e.Token.AccessToken
	dbToken.Refresh = e.Token.RefreshToken
	dbToken.Type = e.Token.TokenType

	//time.Time
	time := e.Token.Expiry
	//dbToken.Expiry = time.String().Format(time.RFC3339)
	dbToken.Expiry = time.Format("2006-01-02 15:04:05.0000000 -0700 MST")
	key := []byte(e.Key)

	// encrypt value to base64
	dbToken.Access, err = encrypt(key, dbToken.Access)
	if err != nil {
		dbToken = models.Token{}
		return
	}
	dbToken.Refresh, err = encrypt(key, dbToken.Refresh)
	if err != nil {
		dbToken = models.Token{}
		return
	}
	dbToken.Type, err = encrypt(key, dbToken.Type)
	if err != nil {
		dbToken = models.Token{}
		return
	}
	dbToken.Expiry, err = encrypt(key, dbToken.Expiry)
	if err != nil {
		dbToken = models.Token{}
		return
	}

	return
}
Esempio n. 19
0
func (s *SchemaDomain) CurDate() (date string) {
	time := time.Now()
	return time.Format("1/2/06")
}
Esempio n. 20
0
func BenchmarkFormat(b *testing.B) {
	time := Unix(1265346057, 0)
	for i := 0; i < b.N; i++ {
		time.Format("Mon Jan  2 15:04:05 2006")
	}
}
Esempio n. 21
0
		case 10:
			return "Sophomore"
		case 11:
			return "Junior"
		case 12:
			return "Senior"
		default:
			return strconv.Itoa(grade)
		}
	},
	"json": func(v interface{}) (string, error) {
		b, err := json.Marshal(v)
		return string(b), err
	},
	"timeFormat": func(format string, time time.Time) string {
		return time.Format(format)
	},
	"timeIn": func(tz string, t time.Time) (time.Time, error) {
		location, err := time.LoadLocation(tz)
		if err != nil {
			return time.Time{}, err
		}
		return t.In(location), nil
	},
	"truncate": func(maxLen int, str string) string {
		if len(str) < maxLen {
			return str
		}
		return str[:maxLen-3] + "..."
	},
	"workerName": func(email, workersJSON string) string {
Esempio n. 22
0
File: time_test.go Progetto: ssrl/go
func BenchmarkFormat(b *testing.B) {
	time := SecondsToLocalTime(1265346057)
	for i := 0; i < b.N; i++ {
		time.Format("Mon Jan  2 15:04:05 2006")
	}
}