Skip to content

Commit 2367773

Browse files
ligeweiregli
andauthored
Improve comments and code style (#63)
Co-authored-by: regli <regli@tencent.com>
1 parent f5c1605 commit 2367773

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

main.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ type Config struct {
3636
// DefaultConfig default config
3737
var DefaultConfig *Config
3838

39-
// New initialize Now based on configuration
39+
// With initializes Now based on configuration
4040
func (config *Config) With(t time.Time) *Now {
4141
return &Now{Time: t, Config: config}
4242
}
4343

44-
// Parse parse string to time based on configuration
44+
// Parse parses string to time based on configuration
4545
func (config *Config) Parse(strs ...string) (time.Time, error) {
4646
if config.TimeLocation == nil {
4747
return config.With(time.Now()).Parse(strs...)
@@ -153,13 +153,12 @@ func EndOfYear() time.Time {
153153
return With(time.Now()).EndOfYear()
154154
}
155155

156-
// Monday monday
157-
156+
// Monday returns the time.Time value of Monday
158157
func Monday(strs ...string) time.Time {
159158
return With(time.Now()).Monday(strs...)
160159
}
161160

162-
// Sunday sunday
161+
// Sunday returns the time.Time value of Sunday
163162
func Sunday(strs ...string) time.Time {
164163
return With(time.Now()).Sunday(strs...)
165164
}

now.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ func (now *Now) Monday() time.Time {
119119
}
120120
*/
121121

122+
// Monday returns the Monday Date of the week specified by now
122123
func (now *Now) Monday(strs ...string) time.Time {
123124
var parseTime time.Time
124125
var err error
@@ -137,6 +138,7 @@ func (now *Now) Monday(strs ...string) time.Time {
137138
return parseTime.AddDate(0, 0, -weekday+1)
138139
}
139140

141+
// Sunday returns the Sunday Date of the week specified by now
140142
func (now *Now) Sunday(strs ...string) time.Time {
141143
var parseTime time.Time
142144
var err error
@@ -180,7 +182,7 @@ func (now *Now) parseWithFormat(str string, location *time.Location) (t time.Tim
180182
var hasTimeRegexp = regexp.MustCompile(`(\s+|^\s*|T)\d{1,2}((:\d{1,2})*|((:\d{1,2}){2}\.(\d{3}|\d{6}|\d{9})))(\s*$|[Z+-])`) // match 15:04:05, 15:04:05.000, 15:04:05.000000 15, 2017-01-01 15:04, 2021-07-20T00:59:10Z, 2021-07-20T00:59:10+08:00, 2021-07-20T00:00:10-07:00 etc
181183
var onlyTimeRegexp = regexp.MustCompile(`^\s*\d{1,2}((:\d{1,2})*|((:\d{1,2}){2}\.(\d{3}|\d{6}|\d{9})))\s*$`) // match 15:04:05, 15, 15:04:05.000, 15:04:05.000000, etc
182184

183-
// Parse parse string to time
185+
// Parse parses string to time
184186
func (now *Now) Parse(strs ...string) (t time.Time, err error) {
185187
var (
186188
setCurrentTime bool

now_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,32 +292,32 @@ func TestParse(t *testing.T) {
292292

293293
assert(With(n).MustParse("2002-10-12T00:14:56+08:00"), "2002-10-12 00:14:56", "Parse 2002-10-12T00:14:56+08:00")
294294
_, off := With(n).MustParse("2002-10-12T00:14:56+08:00").Zone()
295-
if (off != 28800) {
295+
if off != 28800 {
296296
t.Errorf("Parse 2002-10-12T00:14:56+08:00 shouldn't lose time zone offset")
297297
}
298298
assert(With(n).MustParse("2002-10-12T00:00:56-07:00"), "2002-10-12 00:00:56", "Parse 2002-10-12T00:00:56-07:00")
299299
_, off2 := With(n).MustParse("2002-10-12T00:00:56-07:00").Zone()
300-
if (off2 != -25200){
300+
if off2 != -25200 {
301301
t.Errorf("Parse 2002-10-12T00:00:56-07:00 shouldn't lose time zone offset")
302302
}
303303
assert(With(n).MustParse("2002-10-12T00:01:12.333+0200"), "2002-10-12 00:01:12.333", "Parse 2002-10-12T00:01:12.333+0200")
304304
_, off3 := With(n).MustParse("2002-10-12T00:01:12.333+0200").Zone()
305-
if (off3 != 7200){
305+
if off3 != 7200 {
306306
t.Errorf("Parse 2002-10-12T00:01:12.333+0200 shouldn't lose time zone offset")
307307
}
308308
assert(With(n).MustParse("2002-10-12T00:00:56.999999999+08:00"), "2002-10-12 00:00:56.999999999", "Parse 2002-10-12T00:00:56.999999999+08:00")
309309
_, off4 := With(n).MustParse("2002-10-12T00:14:56.999999999+08:00").Zone()
310-
if (off4 != 28800) {
310+
if off4 != 28800 {
311311
t.Errorf("Parse 2002-10-12T00:14:56.999999999+08:00 shouldn't lose time zone offset")
312312
}
313313
assert(With(n).MustParse("2002-10-12T00:00:56.666666-07:00"), "2002-10-12 00:00:56.666666", "Parse 2002-10-12T00:00:56.666666-07:00")
314314
_, off5 := With(n).MustParse("2002-10-12T00:00:56.666666-07:00").Zone()
315-
if (off5 != -25200){
315+
if off5 != -25200 {
316316
t.Errorf("Parse 2002-10-12T00:00:56.666666-07:00 shouldn't lose time zone offset")
317317
}
318318
assert(With(n).MustParse("2002-10-12T00:01:12.999999999-06"), "2002-10-12 00:01:12.999999999", "Parse 2002-10-12T00:01:12.999999999-06")
319319
_, off6 := With(n).MustParse("2002-10-12T00:01:12.999999999-06").Zone()
320-
if (off6 != -21600){
320+
if off6 != -21600 {
321321
t.Errorf("Parse 2002-10-12T00:01:12.999999999-06 shouldn't lose time zone offset")
322322
}
323323

0 commit comments

Comments
 (0)