Skip to content

Commit

Permalink
it
Browse files Browse the repository at this point in the history
  • Loading branch information
shoce committed Sep 1, 2023
0 parents commit de92588
Show file tree
Hide file tree
Showing 5 changed files with 223 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# https://docs.github.com/en/actions/learn-github-actions/contexts
name: release
permissions:
contents: write
on:
push:
branches: [ "main" ]
jobs:
build-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: version
run: |
VERSION=$( date '+%y%m%d.%H%M.0' )
echo "VERSION:$VERSION"
echo "VERSION=$VERSION" >> $GITHUB_ENV
- uses: actions/setup-go@v4
with:
go-version: '^1.21.0'
- name: go build
run: GOOS=linux GOARCH=amd64 go build -o ${{ github.event.repository.name }}.linux.amd64 -trimpath -ldflags '-X main.Version='$VERSION
- name: gzip
run: gzip -k ${{ github.event.repository.name }}.linux.amd64
- name: list files
run: ls -l -a
- name: release notes
run: echo 'curl -sSL https://github.com/shoce/${{ github.event.repository.name }}/releases/latest/download/${{ github.event.repository.name }}.linux.amd64.gz | gunzip | put /bin/${{ github.event.repository.name }} 755' >release.notes..text
- name: gh release
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: gh release create $VERSION ${{ github.event.repository.name }}.linux.amd64.gz --notes-file release.notes..text

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

.DS_Store

3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/shoce/it

go 1.21
182 changes: 182 additions & 0 deletions it.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/*
it = internet time in beats, there are one thousand beats between midnights
usage: it [options]
options:
y = print year since last millenium
d = print date or day number since last january first
s = print seconds or subbeats (there are one hundred subbeats in one beat)
n = not to print time
f = yd = print year, date and time
ff = yds = print year, date, time and seconds/subbeats
v = print string of year and day suitable for version tagging like 20.289
vv = print string of year, day and beats suitable for version tagging like 20.289.499
vvv = print string of year, day and beats and subbeats suitable for version tagging like 20.289.499.38
history:
2020/8/31 copy from tik
20/289 (2020/10/15) add options for version printing and not printing beats but date only
20/209 add options f and ff
21/1215 -m option to show date with months and time in military 24 hour
GoFmt GoBuildNull GoBuild GoRelease GoRun
*/

package main

import (
"fmt"
"os"
"strings"
"time"
)

const (
Beat time.Duration = time.Duration(24) * time.Hour / 1000
)

var (
tzBiel *time.Location
tnow time.Time
td0, ty0 time.Time
)

func militarytimefmt(td time.Duration) string {
return fmt.Sprintf("%02d%02d", int(td/time.Hour), int((td%time.Hour)/time.Minute))
}

func secondsfmt(td time.Duration) string {
return fmt.Sprintf("%02d", int((td%time.Minute)/time.Second))
}

func beatsfmt(td time.Duration) string {
return fmt.Sprintf("%03d", int(td/Beat))
}

func subbeatsfmt(td time.Duration) string {
return fmt.Sprintf("%02d", int((td/(Beat/100))%100))
}

func dayfmt(td time.Duration) string {
day := int(td/(time.Duration(24)*time.Hour)) + 1
return fmt.Sprintf("%03d", day)
}

func monthdayfmt(td time.Duration) string {
return ty0.Add(td).Format("0102")
}

func yearfmt(t time.Time, zeropad bool) (y string) {
if zeropad {
y = fmt.Sprintf("%03d", t.Year()%1000)
} else {
y = fmt.Sprintf("%d", t.Year()%1000)
}
return y
}

func init() {
tzBiel = time.FixedZone("Biel", 60*60)
tnow = time.Now().In(tzBiel)
td0 = time.Date(tnow.Year(), tnow.Month(), tnow.Day(), 0, 0, 0, 0, tzBiel)
ty0 = time.Date(tnow.Year(), 1, 1, 0, 0, 0, 0, tzBiel)
}

func main() {
var ptime, pseconds, pmilitarytime bool
var pdate, pmonthday bool
var pyear bool
var pversion, plongversion, plonglongversion bool
ptime = true
for _, arg := range os.Args[1:] {
if strings.Contains(arg, "y") {
pyear = true
}
if strings.Contains(arg, "d") {
pdate = true
}
if strings.Contains(arg, "m") {
pmonthday = true
pmilitarytime = true
}
if strings.Contains(arg, "s") {
pseconds = true
}
if strings.Contains(arg, "n") {
ptime = false
pseconds = false
}
if strings.Contains(arg, "f") {
pyear = true
pdate = true
ptime = true
}
if strings.Count(arg, "f") > 1 {
pseconds = true
}
if strings.Contains(arg, "v") {
pversion = true
}
if strings.Count(arg, "v") > 1 {
plongversion = true
}
if strings.Count(arg, "v") > 2 {
plonglongversion = true
}
}

td := time.Since(td0)

if pversion || plongversion {
var version string
if pmonthday {
version = fmt.Sprintf("%s.%s", yearfmt(tnow, true), monthdayfmt(time.Since(ty0)))
} else {
version = fmt.Sprintf("%s.%s", yearfmt(tnow, true), dayfmt(time.Since(ty0)))
}
if plongversion {
if pmilitarytime {
version += "." + militarytimefmt(td)
} else {
version += "." + beatsfmt(td)
}
}
if plonglongversion {
if pmilitarytime {
version += "." + secondsfmt(td)
} else {
version += "." + subbeatsfmt(td)
}
}
fmt.Println(version)
return
}

var s string
if ptime {
if pmilitarytime {
s += "@" + militarytimefmt(td)
} else {
s += "@" + beatsfmt(td)
}
}
if pseconds {
if pmilitarytime {
s += "." + secondsfmt(td)
} else {
s += "." + subbeatsfmt(td)
}
}
if pdate {
if pmonthday {
s = monthdayfmt(time.Since(ty0)) + s
} else {
s = dayfmt(time.Since(ty0)) + s
}
}
if pyear {
s = yearfmt(tnow, false) + "/" + s
}

fmt.Println(s)
}
1 change: 1 addition & 0 deletions readme.text
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Decimal internet time in beats, there are one thousand beats between midnights.

0 comments on commit de92588

Please sign in to comment.