//解析星期， 只允许
// 0-6 星期天到星期六
// 0，1 星期日和星期一
// * 忽略
//允许用英文全称和简写
355722
func (c *Crontab) parseWeek(arg string) error {
	set, isticker, err := parseArgument(arg, 0, 6, "week")
	if err != nil {
		return err
	}

	if isticker {
		c.isTicker = true
		v, _ := set.Values()[0].(int)
		c.tickerDuration = time.Hour * 24 * 7 * time.Duration(v)
	}

	c.weekdays = set
	return nil
}
546357
func (z *Lexer) Lexeme() []byte {
	return z.buf[z.start:z.pos]
}
670083
func (e *Epoch) String() string {
	return fmt.Sprintf("Epoch{Time:%d, Level:%d}", e.Time, e.Level)
}
1103301
func (writer *FileLogWriter) Rotate() {
	if writer.wr == nil {
		err := os.MkdirAll(filepath.Dir(writer.config.StorePath), 0666)
		if err != nil {
			panic(fmt.Sprintf("创建日志目录[%s]失败:%s", filepath.Dir(writer.config.StorePath), err))
		}
		fileInfo, err := os.Stat(writer.config.StorePath)
		if err == nil && fileInfo.Size() != 0 {
			bakName := writer.config.StorePath + "." + strconv.FormatInt(time.Now().Unix(), 10)
			err := os.Rename(writer.config.StorePath, bakName)
			if err != nil {
				panic(fmt.Sprintf("备份老的日志文件失败:%s", err))
			}
		}
		writer.wr, err = os.OpenFile(writer.config.StorePath, os.O_CREATE|os.O_RDWR, 0666)
		if err != nil {
			panic(fmt.Sprintf("打开日志文件失败,%s", err))
		}
	} else {
		writer.wr.Close()
		bakName := writer.config.StorePath + "." + strconv.FormatInt(time.Now().Unix(), 10)
		err := os.Rename(writer.config.StorePath, bakName)
		if err != nil {
			Error(fmt.Sprintf("循环备份老的日志文件失败:%s", err))
		}
		file, err := os.Create(writer.config.StorePath)
		if err != nil {
			//日志创建失败直接让程序挂掉
			println(fmt.Sprintf("创建日志文件失败:%s", err))
			panic(fmt.Sprintf("创建日志文件失败:%s", err))
		}
		writer.wr = file
		go clearLog(writer.config.StorePath, writer.config.Rotate)
	}
}
201794
func loadLoggerConfig(loggerConf string) {
	if len(filters) > 0 {
		for _, filter := range filters {
			filter.clear()
		}
	}
	filters = make([]*logFilter, 0)
	conf := parseConfile(loggerConf)
	if conf == nil || len(conf.Appenders) == 0 {
		//fmt.Println("没有指定配置文件,服务将使用默认配置")
		conf = defaultConfig
	}
	for _, appender := range conf.Appenders {
		AddAppender(appender)
	}

}
544805
func (d *TimePeriod_Duration) ToSeconds() (int64, error) {
	// Decompose the duration into a slice of [duration, <int64>, <unit>].
	m := regexp.MustCompile(durationRegex).FindStringSubmatch(d.Duration)
	if len(m) != 3 {
		return 0, errors.Reason("duration must match regex %q", durationRegex).Err()
	}
	n, err := strconv.ParseInt(m[1], 10, 64)
	if err != nil {
		return 0, errors.Reason("duration must not exceed %q", int64(math.MaxInt64)).Err()
	}
	var mul int64
	switch m[2] {
	case "s":
		// 1 second.
		mul = 1
	case "m":
		// 60 seconds.
		mul = 60
	case "h":
		// 60 minutes.
		mul = 3600
	case "d":
		// 24 hours.
		mul = 86400
	case "mo":
		// 30 days.
		mul = 2592000
	}
	if n > math.MaxInt64/mul {
		n = math.MaxInt64
	} else {
		n *= mul
	}
	return n, nil
}
1257926
func (e *Error) Error() string {
	if e.Message != "" {
		return e.Err.Error() + ":" + e.Message
	}

	return e.Err.Error()
}
175588
func (ts timeSequence) Days(days int) []time.Time {
	var values []time.Time
	for day := days; day >= 0; day-- {
		values = append(values, time.Now().AddDate(0, 0, -day))
	}
	return values
}
722606
func parseLyticsTime(ts string) (time.Time, error) {
	var err error

	i, err := strconv.ParseInt(ts, 10, 64)
	if err != nil {
		return time.Now(), err
	}

	tm := time.Unix((i / 1000), 0)

	return tm, err
}
1196445
func SGR(args ...string) string {
	if len(args) == 0 {
		return "\033[" + SGRReset + "m"
	}

	ret := ""
	for _, v := range args {
		ret += v + ";"
	}

	return "\033[" + ret[0:len(ret)-1] + "m"
}
498116
func TranslateDateRef(value string, biases []string, reference time.Time) time.Time {
	year, month, day := TranslateYMD(value, biases)
	if year == 0 {
		year = reference.Year()
	}
	if month == 0 {
		month = int(reference.Month())
	}
	if day == 0 {
		day = reference.Day()
	}
	return time.Date(year, time.Month(month), day, reference.Hour(), reference.Minute(), reference.Second(), reference.Nanosecond(), reference.Location())
}
758917
func parseFlag(flagStr string) (int, error) {
	flagStr = strings.TrimSpace(flagStr)
	if len(flagStr) == 0 {
		return 0, nil
	}

	strs := strings.Split(flagStr, "|")
	ret := 0

	for _, str := range strs {
		str = strings.ToLower(strings.TrimSpace(str))
		flag, found := flagMap[str]
		if !found {
			return 0, errors.New("无效的 flag:" + str)
		}
		ret |= flag
	}

	return ret, nil
}
1201339
func DateLang(lang string) string {
	name, ok := dateLangs[lang]
	if ok {
		return name
	}
	return "en"
}
93148
func (f *TimeFuncs) Unix(in interface{}) (gotime.Time, error) {
	sec, nsec, err := parseNum(in)
	if err != nil {
		return gotime.Time{}, err
	}
	return gotime.Unix(sec, nsec), nil
}
627335
func (writer *baseFileWriter) writef(level LevelType, format string, args ...interface{}) {
	// 格式化构造message
	// 边解析边输出
	// 使用 % 作占位符

	// 统计日志size
	var size = 0

	if writer.closed {
		return
	}

	size = writer.blog.writef(level, format, args...)

	// logrotate
	if writer.sizeRotated || writer.lineRotated {
		writer.logSizeChan <- size
	}

	if nil != writer.hook && !(level < writer.hookLevel) {
		if writer.hookAsync {
			// 异步调用log hook
			go writer.hook.Fire(level, writer.blog.Tags(), fmt.Sprintf(format, args...))
		} else {
			writer.hook.Fire(level, writer.blog.Tags(), fmt.Sprintf(format, args...))
		}
	}
}
366688
func (d *Durafmt) String() string {
	var duration string

	// Check for minus durations.
	if string(d.input[0]) == "-" {
		duration += "-"
		d.duration = -d.duration
	}

	// Convert duration.
	seconds := int64(d.duration.Seconds()) % 60
	minutes := int64(d.duration.Minutes()) % 60
	hours := int64(d.duration.Hours()) % 24
	days := int64(d.duration/(24*time.Hour)) % 365 % 7
	weeks := int64(d.duration/(24*time.Hour)) / 7 % 52
	years := int64(d.duration/(24*time.Hour)) / 365
	milliseconds := int64(d.duration/time.Millisecond) -
		(seconds * 1000) - (minutes * 60000) - (hours * 3600000) -
		(days * 86400000) - (weeks * 604800000) - (years * 31536000000)

	// Create a map of the converted duration time.
	durationMap := map[string]int64{
		"milliseconds": milliseconds,
		"seconds":      seconds,
		"minutes":      minutes,
		"hours":        hours,
		"days":         days,
		"weeks":        weeks,
		"years":        years,
	}

	// Construct duration string.
	for _, u := range units {
		v := durationMap[u]
		if customLable, ok := d.units[u]; ok {
			u = customLable
		}
		strval := strconv.FormatInt(v, 10)
		switch {
		// add to the duration string if v > 1.
		case v > 1:
			duration += strval + " " + u + " "
		// remove the plural 's', if v is 1.
		case v == 1:
			duration += strval + " " + strings.TrimRight(u, "s") + " "
		// omit any value with 0s or 0.
		case d.duration.String() == "0" || d.duration.String() == "0s":
			// note: milliseconds and minutes have the same suffix (m)
			// so we have to check if the units match with the suffix.

			// check for a suffix that is NOT the milliseconds suffix.
			if strings.HasSuffix(d.input, string(u[0])) && !strings.Contains(d.input, "ms") {
				// if it happens that the units are milliseconds, skip.
				if u == "milliseconds" {
					continue
				}
				duration += strval + " " + u
			}
			// process milliseconds here.
			if u == "milliseconds" {
				if strings.Contains(d.input, "ms") {
					duration += strval + " " + u
					break
				}
			}
			break
		// omit any value with 0.
		case v == 0:
			continue
		}
	}
	// trim any remaining spaces.
	duration = strings.TrimSpace(duration)
	return duration
}
153057
func Greeting(r *rand.Rand, name string) string {
	var n int
	if len(name) == 0 {
		n = r.Intn(3)
		switch n {
		case 0:
			return fmt.Sprintf("Hi, %s.", name)
		case 1:
			return fmt.Sprintf("Hello, %s.", name)
		case 2:
			return fmt.Sprintf("Hi there, %s.", name)
		}
	} else {
		n = r.Intn(3)
		switch n {
		case 0:
			return "Hi. How can I help you?"
		case 1:
			return "Hello. What can I do for you?"
		}
	}
	log.Debug("greeting failed to return a response")
	return ""
}