Skip to content

Commit

Permalink
Initial feature complete commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hobysmith committed Sep 7, 2023
1 parent 9dbe173 commit e505df4
Show file tree
Hide file tree
Showing 25 changed files with 3,329 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work

# IDE and Project related files
.idea
timeconverter*
.timeconverter*
545 changes: 545 additions & 0 deletions GUIDE.md

Large diffs are not rendered by default.

96 changes: 96 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
BINARY_NAME=timeconverter
SHORT_DATE := $(shell date +%Y-%m-%d\ %H:%M:%S)
LONG_DATE := $(shell date)
FLAGS := -X 'github.com/hobysmith/timeconverter/cmd.AppShortBuildTime=${SHORT_DATE}' -X 'github.com/hobysmith/timeconverter/cmd.AppLongBuildTime=${LONG_DATE}'
.DEFAULT_GOAL := build

.SILENT:

build:
$(info Building default platform target...)
go build -o ${BINARY_NAME} -ldflags="${FLAGS}"

mac-arm64:
$(info Building Mac ARM64 target...)
GOOS=darwin GOARCH=arm64 go build -o ${BINARY_NAME}-mac-arm64 -ldflags="${FLAGS}"

mac-amd64:
$(info Building Mac AMD64 target...)
GOOS=darwin GOARCH=amd64 go build -o ${BINARY_NAME}-mac-amd64 -ldflags="${FLAGS}"

win-arm64:
$(info Building Windows ARM64 target...)
GOOS=windows GOARCH=arm64 go build -o ${BINARY_NAME}-arm64.exe -ldflags="${FLAGS}"

win-amd64:
$(info Building Windows AMD64 target...)
GOOS=windows GOARCH=amd64 go build -o ${BINARY_NAME}-amd64.exe -ldflags="${FLAGS}"

linux-arm64:
$(info Building Linux ARM64 target...)
GOOS=linux GOARCH=arm64 go build -o ${BINARY_NAME}-linux-arm64 -ldflags="${FLAGS}"

linux-amd64:
$(info Building Linux AMD64 target...)
GOOS=linux GOARCH=amd64 go build -o ${BINARY_NAME}-linux-amd64 -ldflags="${FLAGS}"

bsd:
$(info Building BSD target - Intel support only...)
GOOS=freebsd GOARCH=amd64 go build -o ${BINARY_NAME}-bsd -ldflags="${FLAGS}"

all:
$(info Building all targets...)

$(info Building default platform target...)
go build -o ${BINARY_NAME} -ldflags="${FLAGS}"

$(info Building Mac ARM64 target...)
GOOS=darwin GOARCH=arm64 go build -o ${BINARY_NAME}-mac-arm64 -ldflags="${FLAGS}"

$(info Building Mac AMD64 target...)
GOOS=darwin GOARCH=amd64 go build -o ${BINARY_NAME}-mac-amd64 -ldflags="${FLAGS}"

$(info Building Windows ARM64 target...)
GOOS=windows GOARCH=arm64 go build -o ${BINARY_NAME}-arm64.exe -ldflags="${FLAGS}"

$(info Building Windows AMD64 target...)
GOOS=windows GOARCH=amd64 go build -o ${BINARY_NAME}-amd64.exe -ldflags="${FLAGS}"

$(info Building Linux ARM64 target...)
GOOS=linux GOARCH=arm64 go build -o ${BINARY_NAME}-linux-arm64 -ldflags="${FLAGS}"

$(info Building Linux AMD64 target...)
GOOS=linux GOARCH=amd64 go build -o ${BINARY_NAME}-linux-amd64 -ldflags="${FLAGS}"

$(info Building BSD target - Intel support only...)
GOOS=freebsd GOARCH=amd64 go build -o ${BINARY_NAME}-bsd -ldflags="${FLAGS}"

list:
$(info Available targets)
$(info =====================)
$(info build (or just 'make') - Builds the current platform)
$(info mac-arm64)
$(info mac-amd64)
$(info win-arm64)
$(info win-amd64)
$(info linux-arm64)
$(info linux-amd64)
$(info bsd)
$(info all - builds all targets)
$(info clean - removes all targets that have been built)


clean:
$(info Cleaning GO build artifacts and removing targets...)
go clean
-rm ${BINARY_NAME}-mac-arm64
-rm ${BINARY_NAME}-mac-amd64
-rm ${BINARY_NAME}-arm64.exe
-rm ${BINARY_NAME}-amd64.exe
-rm ${BINARY_NAME}-linux-arm64
-rm ${BINARY_NAME}-linux-amd64
-rm ${BINARY_NAME}-bsd

test:
$(info Running all go tests)
go test ./... -count=1
134 changes: 134 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Timeconverter
**Timeconverter** is a simple, cross-platform commandline utility for
converting time and date values.

**Timeconverter** provides support for 30+ standards and formats, as well as
two forms of custom format definitions. **Timeconverter** also supports
piping input and output via standard OS pipe chains.

While there are other utilities that provide similar functionality as **Timeconverter**,
the goal for this **Timeconverter** utility is to provide simple and consistent behavior with
a single utility across all common platforms.

## Overview
**Timeconverter** is a commandline utility, which uses a simple commandline structure to read a
time value from the commandline using one format, then display that time in another format.

This is the basic structure for converting a time value:

timeconverter timevalue [flags]

The `timevalue` argument can be the word `now` or a time expressed in any of the supported formats.

For example, this command:

timeconverter now -o UnixSecs

will display the current time in Unix seconds format:

Converted Result: 1693668084

And this command:

timeconverter 1693668084 -i UnixSecs -o RFC3339

will read the timevalue in UnixSecs, then convert and display the time in RFC3339 format:

Converted Result: 2023-09-02T10:21:24-05:00

Basically, **Timeconverter** reads the time value using an input format, then outputs the time using an output format.

**Timeconverter** supports all standards defined in the **Go** standard library as of September 2, 2023.
It also supports a number of variants of those standards, plus two custom formats (Custom and CustomGO)
that allow you to define any format of time and date construction you wish.

**Timeconverter** flags allow you to set defaults for input and output formats,
so that you can use a basic syntax like `timeconverter timevalue` to convert
input values using your default input format, then display them in your default output format.

**Timeconverter** supports piping input as well, so you can use it in a standard pipe chain like this:

echo 1693668084 | timeconverter -i UnixSecs -o RFC3339

As well as piping outputs like this:

timeconverter 1693668084 -v | cut -c1-10

## Status
This utility is still in a phase of ongoing development. It is feature complete at this
point, regarding basic expectations of the project. In addition, I have tested it with both
general unit testing coverage and manual testing. All time conversion formats are covered with
unit tests. I believe it is stable and ready for use.

Nevertheless, there may be bugs, as well as missing or incomplete features. Please test for any
specific use-cases you may require. If you do run into issues or have ideas for feature changes,
please submit an issue following the instructions in the section
[Reporting bugs and making feature requests](#reporting-bugs-and-making-feature-requests).

I do have a few more features that I want to add. Any breaking changes should follow versioning semantics,
unless someone finds a core fault I am not aware of. But since I do not expect anyone would use this
code for anything other than the utility itself, I don't expect any dependencies to be affected.

Also, I hope to provide pre-built binaries for the various platforms,
with possible installer type functionality as well, for folks that don't want to build the code themselves.

Finally, I will be updating this GitHub project in several ways.

So, expect that there may be possible changes in the future.

## Installing

You can use the following process to install **Timeconverter** using **Go**'s install functionality:
```
go install github.com/hobysmith/timeconverter@latest
```

If you want to cross-compile a build for one of the supported platforms, do the following:
1. First, clone this repo to your local environment.
2. Then, to build a runtime for the current platform, just run `make`.

Or, to build a runtime for a supported platform, run `make [target]`. The supported targets are:
- mac-arm64
- mac-amd64
- win-arm64
- win-amd64
- linux-arm64
- linux-amd64
- bsd

For example, to build a runtime for Linux on ARM64, run:

make linux-arm64

You can run `make list` to view a list of supported build targets and options.

## Usage
To see standard help info, you can use `timeconverter` or `timeconverter --help` or `timekeeper help`.

To see a list of supported time formats, you can use `timeconverter show -o`.

The **Timeconverter** [Usage Guide](GUIDE.md) provides detailed instructions on all **Timeconverter** functionality,
including setting local and global defaults, additional commands, custom formats,
building for various platforms, etc.

## License
**Timeconverter** uses an MIT license. For license details see [License](LICENSE).

You are welcome to use this utility and code as directed in the MIT License.
My goal is just to provide tools that I actually use myself, with the hope that someone
else may find them useful as well.

## Reporting bugs and making feature requests
Please create an Issue for any bugs you find or suggestions you may have relating to
**Timeconverter** functionality. I will try to respond to these as quickly as I can.

When creating issues for bugs, please prefix the title with "Bug:", like "Bug: Blah Blah feature is not working right."

And for feature requests, please prefix the title with "Feature Request:", like "Feature Request: Adding blah blah functionality would make this utility such the major hotness"

## Contributing
If you wish to contribute, you may fork and submit pull requests.
Please follow this GitHub guide to do so:
[GitHub: Contributing to Projects](https://docs.github.com/en/get-started/quickstart/contributing-to-projects)

I will try to respond to those as I have time.
51 changes: 51 additions & 0 deletions cmd/clear.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2023 - Hoby Smith - [email protected]. All rights reserved.
// Use of this source code is governed by an MIT license that can be found in
// the LICENSE file found in the project's main folder.

package cmd

import (
"fmt"
"github.com/hobysmith/timeconverter/helpers"
"github.com/spf13/cobra"
)

var clearLocal bool
var clearGlobal bool

// clearCmd represents the clear command
var clearCmd = &cobra.Command{
Use: "clear",
Short: "Removes local and global config settings",
Long: "Removes local and global config settings",
Run: func(cmd *cobra.Command, args []string) {
if !clearLocal && !clearGlobal {
_ = cmd.Help()
return
}

if clearLocal {
err := helpers.CmdHelpers.ClearLocalConfig()
if err != nil {
fmt.Printf("Error clearing local config: %s\n", err)
return
}
fmt.Println("Local config removed")
}

if clearGlobal {
err := helpers.CmdHelpers.ClearGlobalConfig()
if err != nil {
fmt.Printf("Error clearing global config: %s\n", err)
return
}
fmt.Println("Global config removed")
}
},
}

func init() {
rootCmd.AddCommand(clearCmd)
clearCmd.Flags().BoolVarP(&clearLocal, "local", "l", false, "If true, will remove the local config file. Default is false.")
clearCmd.Flags().BoolVarP(&clearGlobal, "global", "g", false, "If true, will remove the global config file. Default is false.")
}
Loading

0 comments on commit e505df4

Please sign in to comment.