Skip to content

Commit

Permalink
Merge pull request #10 from jftuga/dev
Browse files Browse the repository at this point in the history
add 'Reformat a date/time' examples
  • Loading branch information
jftuga authored Jul 23, 2024
2 parents 6cb8d64 + fcf5c59 commit 68f99aa
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ before:
hooks:
- go mod tidy
- go generate ./...
- go test

builds:
- id: dtmate
Expand Down
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ The command-line program, `dtmate` *(along with the golang package)* allows you
* * 25771401s
</details>

<details>
<summary>5. Reformat a date/time</summary>

* convert the output of the `date` utility: `dtmate fmt "$(date)" "%F %T"`
* * where `($date)` equals `Mon Jul 22 22:49:18 EDT 2024`
* * output: 2024-07-22 22:49:18
</details>

## Installation

* Library: `go get -u github.com/jftuga/DateTimeMate`
Expand Down Expand Up @@ -289,6 +297,27 @@ $ dtmate conv 25771401s WDhms
# another conversion, in the opposite direction, brief output
$ dtmate conv 42W4D6h43m21s seconds -b
25771401s

########################### "dtmate fmt" examples ###########################

# reformat date/times
$ dtmate fmt "2024-07-22 08:21:44" "%T %D"
08:21:44 07/22/24

$ dtmate fmt "2024-07-22 08:21:44" "%v %r"
22-Jul-2024 08:21:44 AM

$ dtmate fmt "2024-07-22 08:21:44" "%Y%m%d.%H%M%S"
20240722.082144

$ dtmate fmt "2024-02-29T23:59:59Z" "%Y%m%d.%H%M%S"
20240229.235959

$ dtmate fmt "2024-02-29T23:59:59Z" "%Z"
UTC

$ dtmate fmt "Mon Jul 22 08:40:33 EDT 2024" "%Z %z"
EDT -0400
```
</details>

Expand Down
11 changes: 11 additions & 0 deletions cmd/example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,15 @@ func main() {
os.Exit(1)
}
fmt.Println("new duration:", newDuration)

fmt.Println("===================================================")
source = "Mon Jul 22 08:40:33 EDT 2024"
outputFormat := "%F %T"

newFormat, err := DateTimeMate.Reformat(source, outputFormat)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Println("new format:", newFormat)
}

0 comments on commit 68f99aa

Please sign in to comment.