Skip to content

Commit

Permalink
feat: added function justpassed
Browse files Browse the repository at this point in the history
  • Loading branch information
ugol committed Sep 27, 2024
1 parent 39fa02e commit 8d1867d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
4 changes: 2 additions & 2 deletions pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func init() {
ID: "server",
Title: "HTTP Server",
})
rootCmd.PersistentFlags().StringVar(&constants.JR_SYSTEM_DIR, "system_dir", "", "JR system dir")
rootCmd.PersistentFlags().StringVar(&constants.JR_USER_DIR, "user_dir", "", "JR user dir")
rootCmd.PersistentFlags().StringVar(&constants.JR_SYSTEM_DIR, "jr_system_dir", "", "JR system dir")
rootCmd.PersistentFlags().StringVar(&constants.JR_USER_DIR, "jr_user_dir", "", "JR user dir")
rootCmd.PersistentFlags().StringVar(&logLevel, "log_level", constants.DEFAULT_LOG_LEVEL, "HR Log Level")
}

Expand Down
13 changes: 8 additions & 5 deletions pkg/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package cmd

import (
"fmt"
"github.com/jrnd-io/jr/pkg/constants"
"github.com/spf13/cobra"
)

Expand All @@ -34,11 +35,13 @@ var versionCmd = &cobra.Command{
Use: "version",
Short: "prints JR version number",
Long: `prints JR version number`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("JR Version: %s\n", Version)
fmt.Printf("Built with: %s\n", GoVersion)
fmt.Printf(" by: %s\n", BuildUser)
fmt.Printf(" at: %s\n", BuildTime)
Run: func(_ *cobra.Command, _ []string) {
fmt.Printf("JR System Dir: %s\n", constants.JR_SYSTEM_DIR)
fmt.Printf("JR User Dir : %s\n", constants.JR_USER_DIR)
fmt.Printf("JR Version : %s\n", Version)
fmt.Printf("Built with : %s\n", GoVersion)
fmt.Printf("By : %s\n", BuildUser)
fmt.Printf("At : %s\n", BuildTime)
},
}

Expand Down
1 change: 1 addition & 0 deletions pkg/functions/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ var fmap = map[string]interface{}{
"future": Future,
"past": Past,
"recent": Recent,
"justpassed": Justpassed,
"soon": Soon,
"unix_time_stamp": UnixTimeStamp,

Expand Down
10 changes: 10 additions & 0 deletions pkg/functions/functionsDescription.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,16 @@ var funcDesc = map[string]FunctionDescription{
Example: "jr template run --embedded '{{join \"hello,\" \"world\"}}'",
Output: "hello,world",
},
"justpassed": {
Name: "justpassed",
Category: "time",
Description: "returns a date in the past not before the given milliseconds",
Parameters: "milliseconds int",
Localizable: false,
Return: "string",
Example: "jr template run --embedded '{{justpassed 15}}'",
Output: "2024-11-10 22:59:5",
},
"key": {
Name: "key",
Category: "utilities",
Expand Down
10 changes: 10 additions & 0 deletions pkg/functions/timeAndDates.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ func Recent(days int) string {
return d.Format(time.DateOnly)
}

// Justpassed returns a date in the past not before the given milliseconds
func Justpassed(milliseconds int64) string {
now := time.Now()

duration := time.Duration(milliseconds) * time.Millisecond
pastTime := now.Add(-duration)

return pastTime.Format(time.DateTime)
}

// Soon returns a date in the future not after the given days
func Soon(days int) string {
now := time.Now().UTC()
Expand Down

0 comments on commit 8d1867d

Please sign in to comment.