Skip to content

Commit

Permalink
Simplify, add epochtime package
Browse files Browse the repository at this point in the history
  • Loading branch information
curusarn committed Jan 19, 2023
1 parent 4383d2b commit 7d87c38
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 47 deletions.
9 changes: 3 additions & 6 deletions cmd/get-epochtime/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ package main

import (
"fmt"
"time"

"github.com/curusarn/resh/internal/epochtime"
)

// Small utility to get epochtime in millisecond precision
// Doesn't check arguments
// Exits with status 1 on error
func main() {
fmt.Printf("%s", timeToEpochTime(time.Now()))
}

func timeToEpochTime(t time.Time) string {
return fmt.Sprintf("%.2f", float64(t.UnixMilli())/1000)
fmt.Printf("%s", epochtime.Now())
}
3 changes: 3 additions & 0 deletions cmd/postcollect/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/curusarn/resh/internal/cfg"
"github.com/curusarn/resh/internal/collect"
"github.com/curusarn/resh/internal/epochtime"
"github.com/curusarn/resh/internal/logger"
"github.com/curusarn/resh/internal/output"
"github.com/curusarn/resh/internal/recordint"
Expand All @@ -24,6 +25,8 @@ var commit string
var development string

func main() {
epochTime := epochtime.Now()

config, errCfg := cfg.New()
logger, err := logger.New("postcollect", config.LogLevel, development)
if err != nil {
Expand Down
14 changes: 14 additions & 0 deletions internal/epochtime/epochtime.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package epochtime

import (
"fmt"
"time"
)

func TimeToString(t time.Time) string {
return fmt.Sprintf("%.2f", float64(t.UnixMilli())/1000)
}

func Now() string {
return TimeToString(time.Now())
}
18 changes: 18 additions & 0 deletions internal/epochtime/epochtime_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package epochtime

import (
"strconv"
"testing"
"time"
)

func TestConversion(t *testing.T) {
epochTime := "1672702332.64"
seconds, err := strconv.ParseFloat(epochTime, 64)
if err != nil {
t.Fatal("Test setup failed: Failed to convert constant")
}
if TimeToString(time.UnixMilli(int64(seconds*1000))) != epochTime {
t.Fatal("EpochTime changed during conversion")
}
}
5 changes: 5 additions & 0 deletions internal/records/records.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package records

// DEPRECATION NOTICE: This package should be removed in favor of:
// - record: public record definitions
// - recordint: internal record definitions
// - recutil: record-related utils

import (
"bufio"
"os"
Expand Down
28 changes: 26 additions & 2 deletions scripts/hooks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ __resh_precmd() {
if [ -n "${__RESH_COLLECT}" ]; then
if [ "$__RESH_VERSION" != "$(resh-postcollect -version)" ]; then
# shellcheck source=shellrc.sh
source ~/.resh/shellrc
source ~/.resh/shellrc
if [ "$__RESH_VERSION" != "$(resh-postcollect -version)" ]; then
echo "RESH WARNING: You probably just updated RESH - PLEASE RESTART OR RELOAD THIS TERMINAL SESSION (resh version: $(resh-collect -version); resh version of this terminal session: ${__RESH_VERSION})"
else
echo "RESH INFO: New RESH shellrc script was loaded - if you encounter any issues please restart this terminal session."
fi
elif [ "$__RESH_REVISION" != "$(resh-postcollect -revision)" ]; then
# shellcheck source=shellrc.sh
source ~/.resh/shellrc
source ~/.resh/shellrc
if [ "$__RESH_REVISION" != "$(resh-postcollect -revision)" ]; then
echo "RESH WARNING: You probably just updated RESH - PLEASE RESTART OR RELOAD THIS TERMINAL SESSION (resh revision: $(resh-collect -revision); resh revision of this terminal session: ${__RESH_REVISION})"
fi
Expand All @@ -90,3 +90,27 @@ __resh_precmd() {
fi
unset __RESH_COLLECT
}

__resh_session_init() {
if [ "$__RESH_VERSION" != "$(resh-session-init -version)" ]; then
# shellcheck source=shellrc.sh
source ~/.resh/shellrc
if [ "$__RESH_VERSION" != "$(resh-session-init -version)" ]; then
echo "RESH WARNING: You probably just updated RESH - PLEASE RESTART OR RELOAD THIS TERMINAL SESSION (resh version: $(resh-session-init -version); resh version of this terminal session: ${__RESH_VERSION})"
else
echo "RESH INFO: New RESH shellrc script was loaded - if you encounter any issues please restart this terminal session."
fi
elif [ "$__RESH_REVISION" != "$(resh-session-init -revision)" ]; then
# shellcheck source=shellrc.sh
source ~/.resh/shellrc
if [ "$__RESH_REVISION" != "$(resh-session-init -revision)" ]; then
echo "RESH WARNING: You probably just updated RESH - PLEASE RESTART OR RELOAD THIS TERMINAL SESSION (resh revision: $(resh-session-init -revision); resh revision of this terminal session: ${__RESH_REVISION})"
fi
fi
if [ "$__RESH_VERSION" = "$(resh-session-init -version)" ] && [ "$__RESH_REVISION" = "$(resh-session-init -revision)" ]; then
resh-session-init -requireVersion "$__RESH_VERSION" \
-requireRevision "$__RESH_REVISION" \
-sessionId "$__RESH_SESSION_ID" \
-sessionPid "$__RESH_SESSION_PID"
fi
}
27 changes: 0 additions & 27 deletions scripts/util.sh

This file was deleted.

12 changes: 0 additions & 12 deletions test/Dockefile_macoslike

This file was deleted.

0 comments on commit 7d87c38

Please sign in to comment.