mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
827 B
39 lines
827 B
7 years ago
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
||
2 years ago
|
// SPDX-License-Identifier: MIT
|
||
7 years ago
|
|
||
3 years ago
|
package context
|
||
7 years ago
|
|
||
5 years ago
|
import (
|
||
|
"strings"
|
||
|
"time"
|
||
|
)
|
||
7 years ago
|
|
||
5 years ago
|
// GetQueryBeforeSince return parsed time (unix format) from URL query's before and since
|
||
2 years ago
|
func GetQueryBeforeSince(ctx *Base) (before, since int64, err error) {
|
||
1 year ago
|
before, err = parseFormTime(ctx, "before")
|
||
4 years ago
|
if err != nil {
|
||
|
return 0, 0, err
|
||
|
}
|
||
|
|
||
1 year ago
|
since, err = parseFormTime(ctx, "since")
|
||
4 years ago
|
if err != nil {
|
||
|
return 0, 0, err
|
||
|
}
|
||
|
return before, since, nil
|
||
|
}
|
||
|
|
||
|
// parseTime parse time and return unix timestamp
|
||
1 year ago
|
func parseFormTime(ctx *Base, name string) (int64, error) {
|
||
|
value := strings.TrimSpace(ctx.FormString(name))
|
||
4 years ago
|
if len(value) != 0 {
|
||
|
t, err := time.Parse(time.RFC3339, value)
|
||
5 years ago
|
if err != nil {
|
||
4 years ago
|
return 0, err
|
||
5 years ago
|
}
|
||
4 years ago
|
if !t.IsZero() {
|
||
|
return t.Unix(), nil
|
||
5 years ago
|
}
|
||
|
}
|
||
4 years ago
|
return 0, nil
|
||
|
}
|