Ejemplo n.º 1
0
func (this *TimeFrame) parsePreviousNUnits(n int, units string) bool {
	switch units {
	case "minutes":
		this.Start = now.BeginningOfMinute().Add(time.Duration(-n) * time.Minute)
		this.End = now.BeginningOfMinute()
	case "hours":
		this.Start = now.BeginningOfHour().Add(time.Duration(-n) * time.Hour)
		this.End = now.BeginningOfHour()
	case "days":
		this.Start = now.BeginningOfDay().AddDate(0, 0, -n)
		this.End = now.BeginningOfDay()
	case "weeks":
		this.Start = now.BeginningOfWeek().AddDate(0, 0, -n*7)
		this.End = now.BeginningOfWeek()
	case "months":
		this.Start = now.BeginningOfMonth().AddDate(0, -n, 0)
		this.End = now.BeginningOfMonth()
	case "years":
		this.Start = now.BeginningOfYear().AddDate(-n, 0, 0)
		this.End = now.BeginningOfYear()
	default:
		return false
	}
	return true
}
Ejemplo n.º 2
0
func (this *TimeFrame) parseRelUnits(rel string, units string) bool {
	if rel != "this" {
		return false
	}

	switch units {
	case "minute":
		this.Start = now.BeginningOfMinute()
	case "hour":
		this.Start = now.BeginningOfHour()
	case "day":
		this.Start = now.BeginningOfDay()
	case "week":
		this.Start = now.BeginningOfWeek()
	case "month":
		this.Start = now.BeginningOfMonth()
	case "year":
		this.Start = now.BeginningOfYear()
	default:
		return false
	}

	this.End = time.Now()
	return true
}
Ejemplo n.º 3
0
func main() {

	flag.Parse() // Scan the arguments list

	if *quantFlag > 0 && *daysFlag > 0 {

		quant := strconv.Itoa(*quantFlag)
		days := strconv.Itoa(*daysFlag)

		golog, config = startones.Start("config.toml")
		confstr := config.Database.User + ":" + config.Database.Passwd + "@/" + config.Database.Database + "?parseTime=true"
		db, err := sql.Open("mysql", confstr)
		if err != nil {
			golog.Err(err.Error())
		}
		defer db.Close()

		time.Now()

		beginningOfMonth := now.BeginningOfMonth().Format("2006-01-02")

		sqlstr := "select phones.number,phones.provider_id,advertisements.atext from advertisements,phones where journal_id=42 and fromday >= '" + beginningOfMonth + "' and phones.id = advertisements.phone_id and phones.provider_id > 1 order by phones.number"

		//		fmt.Println(sqlstr)

		telmaimosarr := sql2.GetSqlMainosTel(golog, *db, sqlstr)

		sqlstr = "select phone,nmake from aclients where block = 0 and sulje = 0 and ennu = 0 and opcode in (50,54,56,49,79,'na') and nupdate_make <=adddate(now(), -" + days + ") order by id desc limit " + quant

		//		sqlstr = "select phone,nmake from aclients where  phone='0451142458'"
		telmaimosarr_from_aclients := sql2.GetSqlMainosTel(golog, *db, sqlstr)

		smsmainosmaker.CreateSmsOut(golog, *db, telmaimosarr, telmaimosarr_from_aclients)

	} else {

		fmt.Println("try -h")
		//		fmt.Println("try -h ")

	}

}
Ejemplo n.º 4
0
func main() {
	n := time.Now()

	// 標準ライブラリでフォーマットする
	fmt.Println(n)                               // 2016-03-25 19:05:54.785208 +0900 JST
	fmt.Println(n.Format("2006-01-02"))          // 2016-03-25
	fmt.Println(n.Format("2006-01-02 15:04:05")) // 2016-03-25 19:05:54
	fmt.Println(n.Format(time.ANSIC))            // Fri Mar 25 19:05:54 2016
	fmt.Println(n.Format(time.RubyDate))         // Fri Mar 25 19:05:54 +0900 2016
	fmt.Println(n.Format(time.RFC3339))          // 2016-03-25T19:05:54+09:00

	// timeutil を使ってフォーマットする
	fmt.Println(timeutil.Strftime(&n, "%Y-%m-%d"))             // 2016-03-25
	fmt.Println(timeutil.Strftime(&n, "%a %b %d %H:%M:%S %Y")) // Fri Mar 25 19:05:54 2016

	// now を使って日付計算をする
	// 普通に変数名で `now` を使ってると名前解決ができないため、気を付ける必要がありそう
	fmt.Println(now.BeginningOfMonth()) // 2016-03-01 00:00:00 +0900 JST
	fmt.Println(now.EndOfMonth())       // 2016-03-31 23:59:59.999999999 +0900 JST
}
Ejemplo n.º 5
0
func GetDateRef(pattern string) (time.Time, error) {
	var dateRef time.Time
	now.FirstDayMonday = true
	switch pattern {
	case "BeginningOfMinute":
		return now.BeginningOfMinute(), nil
	case "BeginningOfHour":
		return now.BeginningOfHour(), nil
	case "BeginningOfDay":
		return now.BeginningOfDay(), nil
	case "BeginningOfWeek":
		return now.BeginningOfWeek(), nil
	case "BeginningOfMonth":
		return now.BeginningOfMonth(), nil
	case "BeginningOfQuarter":
		return now.BeginningOfQuarter(), nil
	case "BeginningOfYear":
		return now.BeginningOfYear(), nil
	}
	return dateRef, fmt.Errorf("Invalid pattern:%s", pattern)
}