Skip to content

Commit

Permalink
change since, until
Browse files Browse the repository at this point in the history
  • Loading branch information
khw7096 committed Mar 31, 2019
1 parent 0aa52f8 commit db0496c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ From 2019-03-01 to 2019-03-31 : 80h29m10s
$ git hours -help
```

### start, end date
### since, until date
기본적으로 아무값도 넣지 않으면 지난달의 시작일, 마지막일로 설정됩니다.
원한다면 사용자가 아래처럼 시작일, 마지막일을 설정할 수 있습니다.

```
$ git hours -start 2019-02-01 -end 2019-02-28
$ git hours -since 2019-02-01 -until 2019-02-28
```

### set author
Expand Down
30 changes: 15 additions & 15 deletions git-hours.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ func beforeMonth() (string, string) {
} else {
m -= 1
}
start := time.Date(y, m, 1, 0, 0, 0, 0, time.Now().Location())
return fmt.Sprintf(start.Format(DTF)), fmt.Sprintf(start.AddDate(0, 1, 0).Add(-time.Nanosecond).Format(DTF))
since := time.Date(y, m, 1, 0, 0, 0, 0, time.Now().Location())
return fmt.Sprintf(since.Format(DTF)), fmt.Sprintf(since.AddDate(0, 1, 0).Add(-time.Nanosecond).Format(DTF))
}

func thisMonth() (string, string) {
y, m, _ := time.Now().Date()
start := time.Date(y, m, 1, 0, 0, 0, 0, time.Now().Location())
return fmt.Sprintf(start.Format(DTF)), fmt.Sprintf(start.AddDate(0, 1, 0).Add(-time.Nanosecond).Format(DTF))
since := time.Date(y, m, 1, 0, 0, 0, 0, time.Now().Location())
return fmt.Sprintf(since.Format(DTF)), fmt.Sprintf(since.AddDate(0, 1, 0).Add(-time.Nanosecond).Format(DTF))
}

func init() {
Expand All @@ -56,10 +56,10 @@ func init() {
}

func main() {
startMonth, endMonth := beforeMonth()
startPtr := flag.String("start", startMonth, "start date")
since, until := beforeMonth()
sincePtr := flag.String("since", since, "since(after) date")
untilPtr := flag.String("until", until, "until(before) date")
authorPtr := flag.String("author", "", "author name") // git option : --author="\(Adam\)\|\(Jon\)"
endPtr := flag.String("end", endMonth, "end date")
zonePtr := flag.String("zone", initZone, "zone offset time")
debugPtr := flag.Bool("debug", false, "debug mode")
helpPtr := flag.Bool("help", false, "print help")
Expand All @@ -68,13 +68,13 @@ func main() {
flag.PrintDefaults()
os.Exit(0)
}
if !timeFormat.MatchString(*startPtr) {
fmt.Println("not matching start date format. must be " + DTF)
if !timeFormat.MatchString(*sincePtr) {
fmt.Println("not matching since date format. must be " + DTF)
flag.PrintDefaults()
os.Exit(1)
}
if !timeFormat.MatchString(*endPtr) {
fmt.Println("not matching end date format. must be " + DTF)
if !timeFormat.MatchString(*untilPtr) {
fmt.Println("not matching until date format. must be " + DTF)
flag.PrintDefaults()
os.Exit(1)
}
Expand All @@ -95,8 +95,8 @@ func main() {
"--date=iso",
`--pretty=format:%ad %an %s`,
fmt.Sprintf(`--author=%s`, author),
fmt.Sprintf(`--after="%s 00:00:00 %s"`, *startPtr, *zonePtr),
fmt.Sprintf(`--before="%s 23:59:59 %s"`, *endPtr, *zonePtr),
fmt.Sprintf(`--after="%s 00:00:00 %s"`, *sincePtr, *zonePtr),
fmt.Sprintf(`--before="%s 23:59:59 %s"`, *untilPtr, *zonePtr),
)
var stdout bytes.Buffer
var stderr bytes.Buffer
Expand All @@ -117,7 +117,7 @@ func main() {
os.Exit(1)
}
if stdout.String() == "" {
fmt.Printf("From %s to %s : %s\n", *startPtr, *endPtr, total)
fmt.Printf("From %s to %s : %s\n", *sincePtr, *untilPtr, total)
os.Exit(0)
}

Expand Down Expand Up @@ -153,5 +153,5 @@ func main() {
}
before = t
}
fmt.Printf("From %s to %s : %s\n", *startPtr, *endPtr, total)
fmt.Printf("From %s to %s : %s\n", *sincePtr, *untilPtr, total)
}

0 comments on commit db0496c

Please sign in to comment.