✨ Add tools.ParseDate
This commit is contained in:
parent
c01fb53a0e
commit
70b82761c2
8 changed files with 1067 additions and 8 deletions
73
cmd/test.go
Normal file
73
cmd/test.go
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
Copyright © 2024 Dan Jones <danjones@goodevilgenius.org>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"codeberg.org/danjones000/my-log/config"
|
||||
"github.com/spf13/cobra"
|
||||
// "github.com/BurntSushi/toml"
|
||||
dp "github.com/markusmobius/go-dateparser"
|
||||
)
|
||||
|
||||
// testCmd represents the test command
|
||||
var testCmd = &cobra.Command{
|
||||
Use: "test",
|
||||
Short: "A brief description of your command",
|
||||
//Long: ``,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
c, err := config.Load()
|
||||
fmt.Println("error", err)
|
||||
fmt.Printf("%+v\n", c)
|
||||
//ne := "output.stdout.config.json = true"
|
||||
//toml.Decode(ne, &c)
|
||||
st, _ := c.Outputs.Stdout()
|
||||
fmt.Printf("%+v\n", st)
|
||||
//nc := "\n[input]\nrecurse = false\n[output.stdout.config]\njson = true"
|
||||
//toml.Decode(nc, &c)
|
||||
//fmt.Printf("%+v\n", c)
|
||||
d, err := dp.Parse(nil, "now")
|
||||
fmt.Println(d.Time, d.Period)
|
||||
d, err = dp.Parse(nil, "today")
|
||||
fmt.Println(d.Time, d.Period)
|
||||
d, err = dp.Parse(nil, "2 days, 3 minutes ago")
|
||||
fmt.Println(d.Time, d.Period)
|
||||
d, err = dp.Parse(nil, "in 2 decades, 5 days, 3 minutes")
|
||||
fmt.Println(d.Time, d.Period)
|
||||
d, err = dp.Parse(nil, "3 years ago")
|
||||
fmt.Println(d.Time, d.Period)
|
||||
d, err = dp.Parse(nil, "1707711800")
|
||||
fmt.Println(d.Time, d.Period)
|
||||
d, err = dp.Parse(nil, "@1707711800")
|
||||
fmt.Println(d.Time, d.Period)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(testCmd)
|
||||
|
||||
// Here you will define your flags and configuration settings.
|
||||
|
||||
// Cobra supports Persistent Flags which will work for this command
|
||||
// and all subcommands, e.g.:
|
||||
// testCmd.PersistentFlags().String("foo", "", "A help for foo")
|
||||
|
||||
// Cobra supports local flags which will only run when this command
|
||||
// is called directly, e.g.:
|
||||
// testCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue