govaluate icon indicating copy to clipboard operation
govaluate copied to clipboard

Facing issue with the custom function

Open Yash1256 opened this issue 8 months ago • 1 comments

Hi, I have been using govaluate in my code for a long time.. but I faced this issue very recently. The issue is described as I wrote my custom function names as getCustomTimestamp which definition is as below..

"getCustomTimestamp": func(args ...interface{}) (interface{}, error) {
		if len(args) != 1 {
			return nil, ErrInvalidArguments
		}
		fmt.Println("Received args:", args)

		format, ok := args[0].(string)
		if !ok {
			return nil, ErrWrongType
		}

		fmt.Println("Using format:", format)
		if !ok {
			return nil, ErrWrongType
		}
		currentTime := time.Now().In(time.FixedZone("IST", 5*60*60+30*60))
		formattedTime := currentTime.Format(format)
		return formattedTime, nil
	},

And what am I doing is passing string 2024-06-10T09:12:00.084Z to this function and writing an expression which says => getCustomTimestamp("2024-06-10T09:12:00.084Z") or getCustomTimestamp('2024-06-10T09:12:00.084Z') The logs I received are Received args: [1.71801072e+09] whereas if I pass a normal string like your-name then as the output I receive Received args: [your-name], I am not getting this.. is this automatically parsing the time in some format. Please help me here.

Yash1256 avatar Jun 10 '24 10:06 Yash1256