當前位置: 首頁>>代碼示例>>Golang>>正文


Golang common.ParseTimeDuration函數代碼示例

本文整理匯總了Golang中common.ParseTimeDuration函數的典型用法代碼示例。如果您正苦於以下問題:Golang ParseTimeDuration函數的具體用法?Golang ParseTimeDuration怎麽用?Golang ParseTimeDuration使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了ParseTimeDuration函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: ParseAndValidate

func (self *ShardConfiguration) ParseAndValidate(defaultShardDuration time.Duration) error {
	var err error
	if self.Split == 0 {
		self.Split = 1
	}
	if self.SplitRandom == "" {
		self.hasRandomSplit = false
	} else {
		self.hasRandomSplit = true
		self.splitRandomRegex, err = regexp.Compile(self.SplitRandom)
		if err != nil {
			return err
		}
	}
	if self.Duration == "" {
		self.parsedDuration = defaultShardDuration
		return nil
	}
	val, err := common.ParseTimeDuration(self.Duration)
	if err != nil {
		return err
	}
	self.parsedDuration = time.Duration(val)
	return nil
}
開發者ID:peekeri,項目名稱:influxdb,代碼行數:25,代碼來源:configuration.go

示例2: parseTime

// parse time expressions, e.g. now() - 1d
func parseTime(value *Value) (int64, error) {
	if value.Type != ValueExpression {
		if value.IsFunctionCall() && value.Name == "now" {
			return time.Now().UnixNano(), nil
		}

		if value.IsFunctionCall() {
			return 0, fmt.Errorf("Invalid use of function %s", value.Name)
		}

		if value.Type == ValueString {
			t, err := parseTimeString(value.Name)
			return t.UnixNano(), err
		}

		return common.ParseTimeDuration(value.Name)
	}

	leftValue, err := parseTime(value.Elems[0])
	if err != nil {
		return 0, err
	}
	rightValue, err := parseTime(value.Elems[1])
	if err != nil {
		return 0, err
	}
	switch value.Name {
	case "+":
		return leftValue + rightValue, nil
	case "-":
		return leftValue - rightValue, nil
	default:
		return 0, fmt.Errorf("Cannot use '%s' in a time expression", value.Name)
	}
}
開發者ID:sploit,項目名稱:influxdb,代碼行數:36,代碼來源:query_api.go

示例3: GetGroupByTime

func (self GroupByClause) GetGroupByTime() (*time.Duration, error) {
	for _, groupBy := range self.Elems {
		if groupBy.IsFunctionCall() {
			// TODO: check the number of arguments and return an error
			if len(groupBy.Elems) != 1 {
				return nil, common.NewQueryError(common.WrongNumberOfArguments, "time function only accepts one argument")
			}
			// TODO: check the function name
			// TODO: error checking
			arg := groupBy.Elems[0].Name
			durationInt, err := common.ParseTimeDuration(arg)
			if err != nil {
				return nil, common.NewQueryError(common.InvalidArgument, fmt.Sprintf("invalid argument %s to the time function", arg))
			}
			duration := time.Duration(durationInt)
			return &duration, nil
		}
	}
	return nil, nil
}
開發者ID:kennylixi,項目名稱:influxdb,代碼行數:20,代碼來源:group_by.go

示例4: GetGroupByTime

func (self GroupByClause) GetGroupByTime() (*time.Duration, error) {
	for _, groupBy := range self.Elems {
		if groupBy.IsFunctionCall() && strings.ToLower(groupBy.Name) == "time" {
			// TODO: check the number of arguments and return an error
			if len(groupBy.Elems) != 1 {
				return nil, common.NewQueryError(common.WrongNumberOfArguments, "time function only accepts one argument")
			}

			if groupBy.Elems[0].Type != ValueDuration {
				log.Debug("Get a time function without a duration argument %v", groupBy.Elems[0].Type)
			}
			arg := groupBy.Elems[0].Name
			durationInt, err := common.ParseTimeDuration(arg)
			if err != nil {
				return nil, common.NewQueryError(common.InvalidArgument, fmt.Sprintf("invalid argument %s to the time function", arg))
			}
			duration := time.Duration(durationInt)
			return &duration, nil
		}
	}
	return nil, nil
}
開發者ID:hanshenu,項目名稱:influxdb,代碼行數:22,代碼來源:group_by.go


注:本文中的common.ParseTimeDuration函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。