mirror of
https://codeberg.org/scip/ts.git
synced 2025-12-19 05:21:04 +01:00
Compare commits
6 Commits
v0.0.4-cod
...
interface
| Author | SHA1 | Date | |
|---|---|---|---|
| 9dffeadf29 | |||
| 2753e8d483 | |||
| 67d854fbb9 | |||
| 47f4bd455e | |||
| 0038ba2094 | |||
| 84792667e7 |
10
.github/dependabot.yml
vendored
Normal file
10
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "gomod"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "monthly"
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "monthly"
|
||||||
36
.github/workflows/ci.yaml
vendored
Normal file
36
.github/workflows/ci.yaml
vendored
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
name: build-and-test
|
||||||
|
on: [push]
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
version: [1.23.5]
|
||||||
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
|
name: Build
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
steps:
|
||||||
|
- name: Set up Go ${{ matrix.os }}
|
||||||
|
uses: actions/setup-go@v6
|
||||||
|
with:
|
||||||
|
go-version: '${{ matrix.version }}'
|
||||||
|
id: go
|
||||||
|
|
||||||
|
- name: checkout
|
||||||
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
|
- name: build
|
||||||
|
run: go build
|
||||||
|
|
||||||
|
- name: test
|
||||||
|
run: make test
|
||||||
|
|
||||||
|
golangci:
|
||||||
|
name: lint
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/setup-go@v6
|
||||||
|
with:
|
||||||
|
go-version: 1.23
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- name: golangci-lint
|
||||||
|
uses: golangci/golangci-lint-action@v8
|
||||||
87
.github/workflows/release.yaml
vendored
Normal file
87
.github/workflows/release.yaml
vendored
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
name: build-release
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "v*.*.*"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
name: Build Release Assets
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v6
|
||||||
|
with:
|
||||||
|
go-version: 1.23.5
|
||||||
|
|
||||||
|
- name: Build the executables
|
||||||
|
run: ./mkrel.sh ts ${{ github.ref_name}}
|
||||||
|
|
||||||
|
- name: List the executables
|
||||||
|
run: ls -l ./releases
|
||||||
|
|
||||||
|
- name: Upload the binaries
|
||||||
|
uses: svenstaro/upload-release-action@v2
|
||||||
|
with:
|
||||||
|
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
tag: ${{ github.ref_name }}
|
||||||
|
file: ./releases/*
|
||||||
|
file_glob: true
|
||||||
|
|
||||||
|
- name: Build Changelog
|
||||||
|
id: github_release
|
||||||
|
uses: mikepenz/release-changelog-builder-action@v5
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
mode: "PR"
|
||||||
|
configurationJson: |
|
||||||
|
{
|
||||||
|
"template": "#{{CHANGELOG}}\n\n**Full Changelog**: #{{RELEASE_DIFF}}",
|
||||||
|
"pr_template": "- #{{TITLE}} (##{{NUMBER}}) by #{{AUTHOR}}\n#{{BODY}}",
|
||||||
|
"empty_template": "- no changes",
|
||||||
|
"categories": [
|
||||||
|
{
|
||||||
|
"title": "## New Features",
|
||||||
|
"labels": ["add", "feature"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "## Bug Fixes",
|
||||||
|
"labels": ["fix", "bug", "revert"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "## Documentation Enhancements",
|
||||||
|
"labels": ["doc"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "## Refactoring Efforts",
|
||||||
|
"labels": ["refactor"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "## Miscellaneus Changes",
|
||||||
|
"labels": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"ignore_labels": [
|
||||||
|
"duplicate", "good first issue", "help wanted", "invalid", "question", "wontfix"
|
||||||
|
],
|
||||||
|
"label_extractor": [
|
||||||
|
{
|
||||||
|
"pattern": "(.) (.+)",
|
||||||
|
"target": "$1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pattern": "(.) (.+)",
|
||||||
|
"target": "$1",
|
||||||
|
"on_property": "title"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
- name: Create Release
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
body: ${{steps.github_release.outputs.changelog}}
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
|
|
||||||
|
|
||||||
version: 2
|
|
||||||
|
|
||||||
before:
|
|
||||||
hooks:
|
|
||||||
- go mod tidy
|
|
||||||
|
|
||||||
gitea_urls:
|
|
||||||
api: https://codeberg.org/api/v1
|
|
||||||
download: https://codeberg.org
|
|
||||||
|
|
||||||
builds:
|
|
||||||
- env:
|
|
||||||
- CGO_ENABLED=0
|
|
||||||
goos:
|
|
||||||
- linux
|
|
||||||
- windows
|
|
||||||
- darwin
|
|
||||||
- freebsd
|
|
||||||
|
|
||||||
archives:
|
|
||||||
- formats: [tar.gz]
|
|
||||||
# this name template makes the OS and Arch compatible with the results of `uname`.
|
|
||||||
name_template: >-
|
|
||||||
{{ .ProjectName }}_
|
|
||||||
{{- title .Os }}_
|
|
||||||
{{- if eq .Arch "amd64" }}x86_64
|
|
||||||
{{- else if eq .Arch "386" }}i386
|
|
||||||
{{- else }}{{ .Arch }}{{ end }}
|
|
||||||
{{- if .Arm }}v{{ .Arm }}{{ end }}_{{ .Tag }}
|
|
||||||
# use zip for windows archives
|
|
||||||
format_overrides:
|
|
||||||
- goos: windows
|
|
||||||
formats: [zip]
|
|
||||||
- goos: linux
|
|
||||||
formats: [tar.gz,binary]
|
|
||||||
files:
|
|
||||||
- src: "*.md"
|
|
||||||
strip_parent: true
|
|
||||||
- src: "docs/*"
|
|
||||||
strip_parent: true
|
|
||||||
- src: Makefile.dist
|
|
||||||
dst: Makefile
|
|
||||||
wrap_in_directory: true
|
|
||||||
|
|
||||||
changelog:
|
|
||||||
sort: asc
|
|
||||||
filters:
|
|
||||||
exclude:
|
|
||||||
- "^docs:"
|
|
||||||
- "^test:"
|
|
||||||
groups:
|
|
||||||
- title: Improved
|
|
||||||
regexp: '^.*?(feat|add|new)(\([[:word:]]+\))??!?:.+$'
|
|
||||||
order: 0
|
|
||||||
- title: Fixed
|
|
||||||
regexp: '^.*?(bug|fix)(\([[:word:]]+\))??!?:.+$'
|
|
||||||
order: 1
|
|
||||||
- title: Changed
|
|
||||||
order: 999
|
|
||||||
|
|
||||||
release:
|
|
||||||
header: "# Release Notes"
|
|
||||||
footer: >-
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
Full Changelog: [{{ .PreviousTag }}...{{ .Tag }}](https://codeberg.org/scip/ts/compare/{{ .PreviousTag }}...{{ .Tag }})
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
matrix:
|
|
||||||
platform:
|
|
||||||
- linux/amd64
|
|
||||||
goversion:
|
|
||||||
- 1.24
|
|
||||||
|
|
||||||
labels:
|
|
||||||
platform: ${platform}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
build:
|
|
||||||
when:
|
|
||||||
event: [push]
|
|
||||||
image: golang:${goversion}
|
|
||||||
commands:
|
|
||||||
- go get
|
|
||||||
- go build
|
|
||||||
- go test -cover ./...
|
|
||||||
|
|
||||||
test:
|
|
||||||
when:
|
|
||||||
event: [push]
|
|
||||||
image: golang:${goversion}
|
|
||||||
commands:
|
|
||||||
- go get
|
|
||||||
- go test -cover ./...
|
|
||||||
|
|
||||||
linter:
|
|
||||||
when:
|
|
||||||
event: [push]
|
|
||||||
image: golang:${goversion}
|
|
||||||
commands:
|
|
||||||
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.5.0
|
|
||||||
- golangci-lint --version
|
|
||||||
- golangci-lint run ./...
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
# build release
|
|
||||||
|
|
||||||
labels:
|
|
||||||
platform: linux/amd64
|
|
||||||
|
|
||||||
steps:
|
|
||||||
goreleaser:
|
|
||||||
image: goreleaser/goreleaser
|
|
||||||
when:
|
|
||||||
event: [tag]
|
|
||||||
environment:
|
|
||||||
GITEA_TOKEN:
|
|
||||||
from_secret: DEPLOY_TOKEN
|
|
||||||
commands:
|
|
||||||
- goreleaser release --clean --verbose
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
# -*-make-*-
|
|
||||||
|
|
||||||
.PHONY: install all
|
|
||||||
|
|
||||||
tool = ts
|
|
||||||
PREFIX = /usr/local
|
|
||||||
UID = root
|
|
||||||
GID = 0
|
|
||||||
|
|
||||||
all:
|
|
||||||
@echo "Type 'sudo make install' to install the tool."
|
|
||||||
@echo "To change prefix, type 'sudo make install PREFIX=/opt'"
|
|
||||||
|
|
||||||
install:
|
|
||||||
install -d -o $(UID) -g $(GID) $(PREFIX)/bin
|
|
||||||
install -d -o $(UID) -g $(GID) $(PREFIX)/share/doc
|
|
||||||
install -o $(UID) -g $(GID) -m 555 $(tool) $(PREFIX)/sbin/
|
|
||||||
install -o $(UID) -g $(GID) -m 444 *.md $(PREFIX)/share/doc/
|
|
||||||
155
README.md
155
README.md
@@ -2,137 +2,11 @@
|
|||||||
|
|
||||||
generic cli timestamp parser and calculator tool
|
generic cli timestamp parser and calculator tool
|
||||||
|
|
||||||
## Introduction
|
## Usage
|
||||||
|
|
||||||
This little utility is a commandline frontent to the amazing datetime
|
|
||||||
parser module [anytime](https://github.com/ijt/go-anytime). It uses
|
|
||||||
two other modules as fallback if anytime might fail:
|
|
||||||
[now](https://github.com/jinzhu/now) and
|
|
||||||
[dateparse](github.com/araddon/dateparse).
|
|
||||||
|
|
||||||
You can use it to print timestamps from plain english phrases like
|
|
||||||
`next December 23rd AT 5:25 PM` or `two minutes from now`. In addition
|
|
||||||
you can calculate the difference between two timestamps and you can
|
|
||||||
add a duration to a timestamp.
|
|
||||||
|
|
||||||
|
|
||||||
## Example Usage
|
|
||||||
|
|
||||||
In these examples the current time is always **2025-09-17T07:30:00+01:00**.
|
|
||||||
|
|
||||||
Show current date and time (same as `date`):
|
|
||||||
```default
|
|
||||||
% ts now
|
|
||||||
Wed Sep 17 07:30:00 +0100 2025
|
|
||||||
```
|
|
||||||
|
|
||||||
show timestamp for minus 1 hour
|
|
||||||
```default
|
|
||||||
% ts "1 hour ago"
|
|
||||||
Wed Sep 17 06:30:00 +0100 2025
|
|
||||||
```
|
|
||||||
|
|
||||||
... or from a couple days ago:
|
|
||||||
```default
|
|
||||||
% ts "4 days ago"
|
|
||||||
Sat Sep 13 07:30:00 +0100 2025
|
|
||||||
```
|
|
||||||
There are much more ways to get timestamps, see `ts -e`.
|
|
||||||
|
|
||||||
We can also add times to timestamps, here we want to know the
|
|
||||||
timestamp from now plus 10 days and 4 hours in the future:
|
|
||||||
```default
|
|
||||||
% ts -a now 10d4h
|
|
||||||
Sat Sep 27 11:30:00 +0100 2025
|
|
||||||
```
|
|
||||||
|
|
||||||
It doesn't make a difference where you position the `-a` parameter:
|
|
||||||
```default
|
|
||||||
% ts now -a 10d4h
|
|
||||||
Sat Sep 27 11:30:00 +0100 2025
|
|
||||||
```
|
|
||||||
Of course you can also calculate the difference between two
|
|
||||||
dates. Here we have two timestamps (maybe we took them from a log
|
|
||||||
file) and want to know the dime elapsed between them:
|
|
||||||
|
|
||||||
```default
|
```default
|
||||||
% ts 2025-09-17T07:30:00+01:00 2025-09-15T12:45:00+01:00
|
This is ts, a timestamp tool.
|
||||||
42h45m0s
|
|
||||||
```
|
|
||||||
As you can see, if you do not provide a parameter, the default is to
|
|
||||||
calculate the difference between the two args. To explicitly calculate
|
|
||||||
the difference, use the `-d` parameter.
|
|
||||||
|
|
||||||
You can of course use english phrases for time differences as well:
|
|
||||||
```default
|
|
||||||
% ts "today 9 am" 2025-09-15T12:45:00+01:00
|
|
||||||
44h15m0s
|
|
||||||
```
|
|
||||||
|
|
||||||
Lets talk a little bit about formatting. You may have already
|
|
||||||
recognized, that `ts` prints either whole timestamps or
|
|
||||||
durations. Both output types can be modified with the `-f`
|
|
||||||
parameter. There are predefined formats for timestamps:
|
|
||||||
|
|
||||||
```default
|
|
||||||
% ts now
|
|
||||||
Wed Sep 17 07:30:00 +0100 2025
|
|
||||||
% ts now -f rfc3339
|
|
||||||
2025-09-17T07:30:00+01:00
|
|
||||||
% ts now -f date
|
|
||||||
2025-09-17
|
|
||||||
% ts now -f unix
|
|
||||||
1758090600
|
|
||||||
```
|
|
||||||
|
|
||||||
But you can also specify your own, you have to follow the [golang
|
|
||||||
rules for timestamp formats](https://pkg.go.dev/time#Layout),
|
|
||||||
basically:
|
|
||||||
|
|
||||||
* Year: "2006" "06"
|
|
||||||
* Month: "Jan" "January" "01" "1"
|
|
||||||
* Day of the week: "Mon" "Monday"
|
|
||||||
* Day of the month: "2" "_2" "02"
|
|
||||||
* Day of the year: "__2" "002"
|
|
||||||
* Hour: "15" "3" "03" (PM or AM)
|
|
||||||
* Minute: "4" "04"
|
|
||||||
* Second: "5" "05"
|
|
||||||
* AM/PM mark: "PM"
|
|
||||||
|
|
||||||
for example:
|
|
||||||
```default
|
|
||||||
% ts now -f "Mon, 02.January 2006"
|
|
||||||
Wed, 17.September 2025
|
|
||||||
```
|
|
||||||
|
|
||||||
Ok I admit look is kinda weird, complaints go the the golang dev team
|
|
||||||
:).
|
|
||||||
|
|
||||||
Duration formatting is also customizable. By default a duration looks
|
|
||||||
like we have seen above: `44h15m0s`. But sometimes we want to know the
|
|
||||||
number of hours or minutes. Easy:
|
|
||||||
|
|
||||||
```default
|
|
||||||
% ts now 2025-09-15T12:45:00+01:00 -f hours
|
|
||||||
42.75
|
|
||||||
% ts now 2025-09-15T12:45:00+01:00 -f minutes
|
|
||||||
2565.00
|
|
||||||
```
|
|
||||||
|
|
||||||
You may also add the `-u` parameter to have the unit shown as well:
|
|
||||||
|
|
||||||
```default
|
|
||||||
% ts now 2025-09-15T12:45:00+01:00 -f hours -u
|
|
||||||
42.75 hours
|
|
||||||
% ts now 2025-09-15T12:45:00+01:00 -f minutes -u
|
|
||||||
2565.00 minutes
|
|
||||||
```
|
|
||||||
|
|
||||||
## Commandline parameters
|
|
||||||
|
|
||||||
Here is the list of all supported parameters:
|
|
||||||
|
|
||||||
```default
|
|
||||||
Usage: ts <time string> [<time string>]
|
Usage: ts <time string> [<time string>]
|
||||||
-d --diff Calculate difference between two timestamps (default).
|
-d --diff Calculate difference between two timestamps (default).
|
||||||
-a --add Add two timestamps (second parameter must be a time).
|
-a --add Add two timestamps (second parameter must be a time).
|
||||||
@@ -147,6 +21,27 @@ Usage: ts <time string> [<time string>]
|
|||||||
-e --examples Show examples or supported inputs.
|
-e --examples Show examples or supported inputs.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
```default
|
||||||
|
# diff between to day and yesterday 10 am
|
||||||
|
ts today "10am yesterday"
|
||||||
|
14h0m0s
|
||||||
|
|
||||||
|
# show timestamp from a couple days ago
|
||||||
|
ts "3 days ago"
|
||||||
|
2025-09-21 13:51:55.054754744 +0200 CEST
|
||||||
|
|
||||||
|
# show timestamp of one hour and 45 minutes before (-d is the defaul)
|
||||||
|
ts -d now 1h45m
|
||||||
|
2025-09-24 12:07:45.072300157 +0200 CEST m=-6299.999710536
|
||||||
|
|
||||||
|
# 10 hours from now
|
||||||
|
ts now 10h
|
||||||
|
2025-09-24 03:53:36.7095512 +0200 CEST m=-35999.999720767
|
||||||
|
```
|
||||||
|
|
||||||
|
To see a comprehensive list of supported inputs, call `ts -e`.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@@ -155,7 +50,7 @@ your platform from the releases page and you're good to go.
|
|||||||
|
|
||||||
### Installation using a pre-compiled binary
|
### Installation using a pre-compiled binary
|
||||||
|
|
||||||
Go to the [latest release page](https://codeberg.org/scip/ts/releases/latest)
|
Go to the [latest release page](https://github.com/TLINDEN/ts/releases/latest)
|
||||||
and look for your OS and platform. There are two options to install the binary:
|
and look for your OS and platform. There are two options to install the binary:
|
||||||
|
|
||||||
Directly download the binary for your platform,
|
Directly download the binary for your platform,
|
||||||
@@ -196,7 +91,7 @@ install`.
|
|||||||
|
|
||||||
# Report bugs
|
# Report bugs
|
||||||
|
|
||||||
[Please open an issue](https://codeberg.org/scip/ts/issues). Thanks!
|
[Please open an issue](https://github.com/TLINDEN/ts/issues). Thanks!
|
||||||
|
|
||||||
# License
|
# License
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/knadh/koanf/providers/posflag"
|
"github.com/knadh/koanf/providers/posflag"
|
||||||
"github.com/knadh/koanf/v2"
|
"github.com/knadh/koanf/v2"
|
||||||
@@ -32,7 +31,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VERSIONstring = "0.0.4"
|
VERSIONstring = "0.0.2"
|
||||||
Usage string = `This is ts, a timestamp tool.
|
Usage string = `This is ts, a timestamp tool.
|
||||||
|
|
||||||
Usage: ts <time string> [<time string>]
|
Usage: ts <time string> [<time string>]
|
||||||
@@ -77,11 +76,8 @@ noon Yesterday at 10:15am Mon, 02 Jan 2006 15:
|
|||||||
Example durations for second parameter:
|
Example durations for second parameter:
|
||||||
2d1h30m 2 days, one and a half hour
|
2d1h30m 2 days, one and a half hour
|
||||||
30m 30 minutes`
|
30m 30 minutes`
|
||||||
|
|
||||||
ModeDiff int = iota
|
ModeDiff int = iota
|
||||||
ModeAdd
|
ModeAdd
|
||||||
|
|
||||||
DefaultFormat string = "Mon Jan 02 15:04:05 MST 2006"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
@@ -96,10 +92,6 @@ type Config struct {
|
|||||||
Args []string
|
Args []string
|
||||||
Output io.Writer
|
Output io.Writer
|
||||||
Mode int
|
Mode int
|
||||||
|
|
||||||
// internal flags for [unit] tests
|
|
||||||
tz string // has to be set directly in code
|
|
||||||
refTime time.Time // must be set via env var $TSREFTIME
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitConfig(output io.Writer) (*Config, error) {
|
func InitConfig(output io.Writer) (*Config, error) {
|
||||||
@@ -134,30 +126,17 @@ func InitConfig(output io.Writer) (*Config, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fetch values
|
// fetch values
|
||||||
conf := &Config{Output: output, refTime: time.Now()}
|
conf := &Config{Output: output}
|
||||||
if err := kloader.Unmarshal("", &conf); err != nil {
|
if err := kloader.Unmarshal("", &conf); err != nil {
|
||||||
return nil, fmt.Errorf("error unmarshalling: %w", err)
|
return nil, fmt.Errorf("error unmarshalling: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// check internal env var[s], if any
|
|
||||||
reftime, present := os.LookupEnv("TSREFTIME")
|
|
||||||
if present {
|
|
||||||
// e.g: 2014-01-03T00:00:00+01:00
|
|
||||||
ts, err := time.Parse(time.RFC3339Nano, reftime)
|
|
||||||
if err != nil {
|
|
||||||
os.Exit(Die("failed to set reference time from $TSREFTIME", err))
|
|
||||||
}
|
|
||||||
|
|
||||||
conf.refTime = ts
|
|
||||||
}
|
|
||||||
|
|
||||||
// want examples?
|
// want examples?
|
||||||
if conf.Examples {
|
if conf.Examples {
|
||||||
_, err := fmt.Fprintln(output, Examples)
|
_, err := fmt.Fprintln(output, Examples)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Die("failed write to output file handle", err)
|
Die(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
12
cmd/root.go
12
cmd/root.go
@@ -18,13 +18,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Die(format string, err error) int {
|
func Die(err error) int {
|
||||||
fmt.Fprintf(os.Stderr, format+": %s\n", err)
|
log.Fatal("Error: ", err.Error())
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
@@ -32,14 +31,13 @@ func Die(format string, err error) int {
|
|||||||
func Main(output io.Writer) int {
|
func Main(output io.Writer) int {
|
||||||
conf, err := InitConfig(output)
|
conf, err := InitConfig(output)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(1)
|
return Die(err)
|
||||||
return Die("failed to initialize", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tp := NewTP(conf)
|
tp := NewTP(conf)
|
||||||
|
|
||||||
if err := tp.ProcessTimestamps(); err != nil {
|
if err := tp.ProcessTimestamps(); err != nil {
|
||||||
return Die("failed to process timestamp[s]", err)
|
return Die(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
50
cmd/times.go
50
cmd/times.go
@@ -20,12 +20,13 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/araddon/dateparse"
|
|
||||||
"github.com/ijt/go-anytime"
|
"github.com/ijt/go-anytime"
|
||||||
|
"github.com/itlightning/dateparse"
|
||||||
modnow "github.com/jinzhu/now"
|
modnow "github.com/jinzhu/now"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -45,10 +46,9 @@ func NewTP(conf *Config, ref ...time.Time) *TimestampProccessor {
|
|||||||
|
|
||||||
modnow.TimeFormats = append(modnow.TimeFormats, formats...)
|
modnow.TimeFormats = append(modnow.TimeFormats, formats...)
|
||||||
|
|
||||||
tp := &TimestampProccessor{Config: *conf, Reference: conf.refTime}
|
tp := &TimestampProccessor{Config: *conf, Reference: time.Now()}
|
||||||
|
|
||||||
if len(ref) == 1 {
|
if len(ref) == 1 {
|
||||||
// overwritten externally by unit test
|
|
||||||
tp.Reference = ref[0]
|
tp.Reference = ref[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,31 +60,25 @@ func (tp *TimestampProccessor) ProcessTimestamps() error {
|
|||||||
case 1:
|
case 1:
|
||||||
return tp.SingleTimestamp(tp.Args[0])
|
return tp.SingleTimestamp(tp.Args[0])
|
||||||
case 2:
|
case 2:
|
||||||
return tp.DualTimestamps(tp.Args[0], tp.Args[1])
|
return tp.Calc(tp.Args[0], tp.Args[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// a post processor for ParseTimestamp() to apply custom time zone, if any
|
func (tp *TimestampProccessor) SingleTimestamp(timestamp string) error {
|
||||||
func (tp *TimestampProccessor) Parse(timestamp string) (time.Time, error) {
|
ts, err := tp.Parse(timestamp)
|
||||||
ts, err := tp.ParseTimestamp(timestamp)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ts, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if tp.tz != "" {
|
tp.Print(ts)
|
||||||
// apply custom timezone
|
|
||||||
zone, _ := time.LoadLocation(tp.tz)
|
|
||||||
ts = ts.In(zone)
|
|
||||||
}
|
|
||||||
|
|
||||||
return ts, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse uses 3 different timestamp parser modules to provide maximum flexibility
|
// Parse uses 3 different timestamp parser modules to provide maximum flexibility
|
||||||
func (tp *TimestampProccessor) ParseTimestamp(timestamp string) (time.Time, error) {
|
func (tp *TimestampProccessor) Parse(timestamp string) (time.Time, error) {
|
||||||
ts, err := anytime.Parse(timestamp, tp.Reference)
|
ts, err := anytime.Parse(timestamp, tp.Reference)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return ts, nil
|
return ts, nil
|
||||||
@@ -100,19 +94,7 @@ func (tp *TimestampProccessor) ParseTimestamp(timestamp string) (time.Time, erro
|
|||||||
return dateparse.ParseAny(timestamp)
|
return dateparse.ParseAny(timestamp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tp *TimestampProccessor) SingleTimestamp(timestamp string) error {
|
func (tp *TimestampProccessor) Calc(timestampA, timestampB string) error {
|
||||||
ts, err := tp.Parse(timestamp)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
tp.Print(TPdatetime{TimestampProccessor: *tp, Data: ts})
|
|
||||||
//tp.Print(ts)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tp *TimestampProccessor) DualTimestamps(timestampA, timestampB string) error {
|
|
||||||
tsA, err := tp.Parse(timestampA)
|
tsA, err := tp.Parse(timestampA)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -130,12 +112,6 @@ func (tp *TimestampProccessor) DualTimestamps(timestampA, timestampB string) err
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
tp.CalcDiff(tsA, tsB)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (tp *TimestampProccessor) CalcDiff(tsA time.Time, tsB time.Time) {
|
|
||||||
switch tp.Mode {
|
switch tp.Mode {
|
||||||
case ModeDiff:
|
case ModeDiff:
|
||||||
var diff time.Duration
|
var diff time.Duration
|
||||||
@@ -155,6 +131,8 @@ func (tp *TimestampProccessor) CalcDiff(tsA time.Time, tsB time.Time) {
|
|||||||
|
|
||||||
tp.Print(TPdatetime{TimestampProccessor: *tp, Data: sum})
|
tp.Print(TPdatetime{TimestampProccessor: *tp, Data: sum})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tp *TimestampProccessor) CalcDuration(tsA time.Time, durB time.Duration) {
|
func (tp *TimestampProccessor) CalcDuration(tsA time.Time, durB time.Duration) {
|
||||||
@@ -173,7 +151,7 @@ func (tp *TimestampProccessor) CalcDuration(tsA time.Time, durB time.Duration) {
|
|||||||
func (tp *TimestampProccessor) Print(ts TimestampWriter) {
|
func (tp *TimestampProccessor) Print(ts TimestampWriter) {
|
||||||
_, err := fmt.Fprintln(tp.Output, ts.String())
|
_, err := fmt.Fprintln(tp.Output, ts.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Die("failed to print to given output handle", err)
|
log.Fatalf("failed to print to given output handle: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,15 +65,13 @@ func TestParseTimestamps(t *testing.T) {
|
|||||||
{`One year ago`, now.AddDate(-1, 0, 0)},
|
{`One year ago`, now.AddDate(-1, 0, 0)},
|
||||||
{`03:15`, dateAtTime(now, 3, 15, 0)},
|
{`03:15`, dateAtTime(now, 3, 15, 0)},
|
||||||
{`Wed Sep 25 12:30:00 PM UTC 2025`, now},
|
{`Wed Sep 25 12:30:00 PM UTC 2025`, now},
|
||||||
{`Wed Sep 25 00:30:00 PM CEST 2025`, now},
|
|
||||||
{`Wed Sep 25 2025 13:30:00 GMT+0100 (GMT Daylight Time)`, now},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range datetimes {
|
for _, tt := range datetimes {
|
||||||
testname := fmt.Sprintf("parsetimestamp-%s", strings.ReplaceAll(tt.input, " ", "-"))
|
testname := fmt.Sprintf("parsetimestamp-%s", strings.ReplaceAll(tt.input, " ", "-"))
|
||||||
t.Run(testname, func(t *testing.T) {
|
t.Run(testname, func(t *testing.T) {
|
||||||
var writer bytes.Buffer
|
var writer bytes.Buffer
|
||||||
tp := NewTP(&Config{Args: []string{tt.input}, Output: &writer, tz: "UTC"}, now)
|
tp := NewTP(&Config{Args: []string{tt.input}, Output: &writer}, now)
|
||||||
|
|
||||||
// writer.String()
|
// writer.String()
|
||||||
ts, err := tp.Parse(tt.input)
|
ts, err := tp.Parse(tt.input)
|
||||||
@@ -82,7 +80,7 @@ func TestParseTimestamps(t *testing.T) {
|
|||||||
|
|
||||||
err = tp.ProcessTimestamps()
|
err = tp.ProcessTimestamps()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, tt.want.Format(DefaultFormat)+"\n", writer.String())
|
assert.EqualValues(t, tt.want.String()+"\n", writer.String())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -148,7 +146,7 @@ func TestAddTimestamps(t *testing.T) {
|
|||||||
|
|
||||||
err := tp.ProcessTimestamps()
|
err := tp.ProcessTimestamps()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, tt.want.Format(DefaultFormat)+"\n", writer.String())
|
assert.EqualValues(t, tt.want.String()+"\n", writer.String())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ func (duration TPduration) String() string {
|
|||||||
// duration, days, hour, min, sec, msec
|
// duration, days, hour, min, sec, msec
|
||||||
switch duration.Format {
|
switch duration.Format {
|
||||||
case "d", "day", "days":
|
case "d", "day", "days":
|
||||||
return fmt.Sprintf("%.02f%s", duration.Data.Hours()/24, unit)
|
return fmt.Sprintf("%.02f%s", duration.Data.Hours()/24+(duration.Data.Minutes()/60), unit)
|
||||||
case "h", "hour", "hours":
|
case "h", "hour", "hours":
|
||||||
return fmt.Sprintf("%.02f%s", duration.Data.Hours(), unit)
|
return fmt.Sprintf("%.02f%s", duration.Data.Hours(), unit)
|
||||||
case "m", "min", "mins", "minutes":
|
case "m", "min", "mins", "minutes":
|
||||||
@@ -87,7 +87,7 @@ func (datetime TPdatetime) String() string {
|
|||||||
case "datetime":
|
case "datetime":
|
||||||
fallthrough
|
fallthrough
|
||||||
case "":
|
case "":
|
||||||
return datetime.Data.Format(DefaultFormat)
|
return datetime.Data.String()
|
||||||
default:
|
default:
|
||||||
return datetime.Data.Format(datetime.Format)
|
return datetime.Data.Format(datetime.Format)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,81 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright © 2025 Thomas von Dein
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package cmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestDuration(t *testing.T) {
|
|
||||||
var tests = []struct {
|
|
||||||
format string
|
|
||||||
duration time.Duration
|
|
||||||
want string
|
|
||||||
}{
|
|
||||||
{"day", time.Hour * 24, "1.00 days"},
|
|
||||||
{"dur", time.Hour * 24, "24h0m0s"},
|
|
||||||
{"hour", time.Hour * 24, "24.00 hours"},
|
|
||||||
{"min", time.Minute * 20, "20.00 minutes"},
|
|
||||||
{"min", time.Minute*20 + time.Second*30, "20.50 minutes"},
|
|
||||||
{"sec", time.Second * 30, "30.00 seconds"},
|
|
||||||
{"ms", time.Second * 30, "30000 milliseconds"},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
|
||||||
testname := fmt.Sprintf("formatduration-%s", tt.format)
|
|
||||||
t.Run(testname, func(t *testing.T) {
|
|
||||||
tpdur := TPduration{Data: tt.duration}
|
|
||||||
tpdur.Unit = true
|
|
||||||
tpdur.Format = tt.format
|
|
||||||
|
|
||||||
out := tpdur.String()
|
|
||||||
assert.Equal(t, tt.want, out)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDatetime(t *testing.T) {
|
|
||||||
var now = time.Date(2025, 9, 25, 12, 30, 00, 0, time.UTC)
|
|
||||||
|
|
||||||
var tests = []struct {
|
|
||||||
format string
|
|
||||||
datetime time.Time
|
|
||||||
want string
|
|
||||||
}{
|
|
||||||
{"rfc3339", now, "2025-09-25T12:30:00Z"},
|
|
||||||
{"date", now, "2025-09-25"},
|
|
||||||
{"time", now, "12:30:00"},
|
|
||||||
{"unix", now, "1758803400"},
|
|
||||||
{"datetime", now, "Thu Sep 25 12:30:00 UTC 2025"},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
|
||||||
testname := fmt.Sprintf("formatdatetime-%s", tt.format)
|
|
||||||
t.Run(testname, func(t *testing.T) {
|
|
||||||
tpdat := TPdatetime{Data: tt.datetime}
|
|
||||||
tpdat.Format = tt.format
|
|
||||||
|
|
||||||
out := tpdat.String()
|
|
||||||
assert.Equal(t, tt.want, out)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
6
go.mod
6
go.mod
@@ -1,11 +1,10 @@
|
|||||||
module codeberg.org/scip/ts
|
module github.com/tlinden/ts
|
||||||
|
|
||||||
go 1.23.0
|
go 1.23.0
|
||||||
|
|
||||||
toolchain go1.23.5
|
toolchain go1.23.5
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de // indirect
|
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
|
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
|
||||||
github.com/ijt/go-anytime v1.9.2 // indirect
|
github.com/ijt/go-anytime v1.9.2 // indirect
|
||||||
@@ -18,10 +17,7 @@ require (
|
|||||||
github.com/mitchellh/copystructure v1.2.0 // indirect
|
github.com/mitchellh/copystructure v1.2.0 // indirect
|
||||||
github.com/mitchellh/reflectwalk v1.0.2 // indirect
|
github.com/mitchellh/reflectwalk v1.0.2 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/rogpeppe/go-internal v1.14.1 // indirect
|
|
||||||
github.com/spf13/pflag v1.0.10 // indirect
|
github.com/spf13/pflag v1.0.10 // indirect
|
||||||
github.com/stretchr/testify v1.11.1 // indirect
|
github.com/stretchr/testify v1.11.1 // indirect
|
||||||
golang.org/x/sys v0.26.0 // indirect
|
|
||||||
golang.org/x/tools v0.26.0 // indirect
|
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
15
go.sum
15
go.sum
@@ -1,6 +1,3 @@
|
|||||||
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de h1:FxWPpzIjnTlhPwqqXc4/vE0f7GvRjuAsbW+HOIe8KnA=
|
|
||||||
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de/go.mod h1:DCaWoUhZrYW9p1lxo/cm8EmUOOzAPSEZNGF2DK1dJgw=
|
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
|
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
|
||||||
@@ -19,28 +16,16 @@ github.com/knadh/koanf/providers/posflag v1.0.1 h1:EnMxHSrPkYCFnKgBUl5KBgrjed8gV
|
|||||||
github.com/knadh/koanf/providers/posflag v1.0.1/go.mod h1:3Wn3+YG3f4ljzRyCUgIwH7G0sZ1pMjCOsNBovrbKmAk=
|
github.com/knadh/koanf/providers/posflag v1.0.1/go.mod h1:3Wn3+YG3f4ljzRyCUgIwH7G0sZ1pMjCOsNBovrbKmAk=
|
||||||
github.com/knadh/koanf/v2 v2.3.0 h1:Qg076dDRFHvqnKG97ZEsi9TAg2/nFTa9hCdcSa1lvlM=
|
github.com/knadh/koanf/v2 v2.3.0 h1:Qg076dDRFHvqnKG97ZEsi9TAg2/nFTa9hCdcSa1lvlM=
|
||||||
github.com/knadh/koanf/v2 v2.3.0/go.mod h1:gRb40VRAbd4iJMYYD5IxZ6hfuopFcXBpc9bbQpZwo28=
|
github.com/knadh/koanf/v2 v2.3.0/go.mod h1:gRb40VRAbd4iJMYYD5IxZ6hfuopFcXBpc9bbQpZwo28=
|
||||||
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
|
|
||||||
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
|
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
|
||||||
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
|
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
|
||||||
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
|
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
|
||||||
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
|
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
|
||||||
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
|
|
||||||
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
|
|
||||||
github.com/scylladb/termtables v0.0.0-20191203121021-c4c0b6d42ff4/go.mod h1:C1a7PQSMz9NShzorzCiG2fk9+xuCgLkPeCvMHYR2OWg=
|
|
||||||
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
|
github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk=
|
||||||
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
|
||||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||||
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
|
|
||||||
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
|
||||||
golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ=
|
|
||||||
golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|||||||
2
main.go
2
main.go
@@ -20,7 +20,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"codeberg.org/scip/ts/cmd"
|
"github.com/tlinden/ts/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|||||||
38
main_test.go
38
main_test.go
@@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright © 2025 Thomas von Dein
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/rogpeppe/go-internal/testscript"
|
|
||||||
)
|
|
||||||
|
|
||||||
// see https://bitfieldconsulting.com/golang/test-scripts
|
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
|
||||||
testscript.Main(m, map[string]func(){
|
|
||||||
"ts": main,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func Test_TS(t *testing.T) {
|
|
||||||
testscript.Run(t, testscript.Params{
|
|
||||||
Dir: "t",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
70
mkrel.sh
Executable file
70
mkrel.sh
Executable file
@@ -0,0 +1,70 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Copyright © 2024 Thomas von Dein
|
||||||
|
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
# get list with: go tool dist list
|
||||||
|
DIST="darwin/amd64
|
||||||
|
freebsd/amd64
|
||||||
|
linux/amd64
|
||||||
|
windows/amd64
|
||||||
|
freebsd/arm64
|
||||||
|
linux/arm64"
|
||||||
|
|
||||||
|
tool="$1"
|
||||||
|
version="$2"
|
||||||
|
|
||||||
|
if test -z "$version"; then
|
||||||
|
echo "Usage: $0 <tool name> <release version>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -rf releases
|
||||||
|
mkdir -p releases
|
||||||
|
|
||||||
|
|
||||||
|
for D in $DIST; do
|
||||||
|
os=${D/\/*/}
|
||||||
|
arch=${D/*\//}
|
||||||
|
binfile="releases/${tool}-${os}-${arch}-${version}"
|
||||||
|
|
||||||
|
if test "$os" = "windows"; then
|
||||||
|
binfile="${binfile}.exe"
|
||||||
|
fi
|
||||||
|
|
||||||
|
tardir="${tool}-${os}-${arch}-${version}"
|
||||||
|
tarfile="releases/${tool}-${os}-${arch}-${version}.tar.gz"
|
||||||
|
set -x
|
||||||
|
GOOS=${os} GOARCH=${arch} go build -tags osusergo,netgo -ldflags "-extldflags=-static" -o ${binfile}
|
||||||
|
mkdir -p ${tardir}
|
||||||
|
cp ${binfile} README.md LICENSE ${tardir}/
|
||||||
|
echo 'tool = ts
|
||||||
|
PREFIX = /usr/local
|
||||||
|
UID = root
|
||||||
|
GID = 0
|
||||||
|
|
||||||
|
install:
|
||||||
|
install -d -o $(UID) -g $(GID) $(PREFIX)/bin
|
||||||
|
install -d -o $(UID) -g $(GID) $(PREFIX)/man/man1
|
||||||
|
install -o $(UID) -g $(GID) -m 555 $(tool) $(PREFIX)/sbin/
|
||||||
|
install -o $(UID) -g $(GID) -m 444 $(tool).1 $(PREFIX)/man/man1/' > ${tardir}/Makefile
|
||||||
|
tar cpzf ${tarfile} ${tardir}
|
||||||
|
sha256sum ${binfile} | cut -d' ' -f1 > ${binfile}.sha256
|
||||||
|
sha256sum ${tarfile} | cut -d' ' -f1 > ${tarfile}.sha256
|
||||||
|
rm -rf ${tardir}
|
||||||
|
set +x
|
||||||
|
done
|
||||||
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
exec ts -h
|
|
||||||
stdout 'This is ts'
|
|
||||||
|
|
||||||
exec ts -e
|
|
||||||
stdout 'yesterday'
|
|
||||||
|
|
||||||
exec ts 3/1/2014
|
|
||||||
stdout 'Fri Jan 03'
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user