Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

text.Scanner is outputting unnecessary stderr #58

Open
arran4 opened this issue Feb 16, 2023 · 3 comments
Open

text.Scanner is outputting unnecessary stderr #58

arran4 opened this issue Feb 16, 2023 · 3 comments

Comments

@arran4
Copy link

arran4 commented Feb 16, 2023

text.Scanner is outputting errors. Such as:

<input>:1:1: literal not terminated
<input>:1:1: invalid char literal
<input>:1:1: literal not terminated
<input>:1:1: invalid char literal

Such as when I use tokens like '':

		layoutData{
			layout: "' Mon, 2 Jan 2006 15:4:5 -0700",
			matches: []string{
				"' Нд, 22 Гру 2019 00:35:44 +0200",
			},
			unmatches: []string{},
			locales: []Locale{
				LocaleUkUA,
				LocaleRuRU,
				LocaleEnUS,
				LocaleEnUS,
			},
		},

I believe this is because text.Scanner is build to parse go tokens for a compiler.

Which technically means I should be able to break tests by passing in tokens like /* and when it /could/ be a valid format string.

Ie:

package main

import (
	"fmt"
	"github.com/goodsign/monday"
	"time"
)

func main() {
	fmt.Println(time.Parse("/* Mon, 02 Jan 2006 15:04:05 */", "/* Mon, 02 Nov 2007 17:42:36 */"))
	fmt.Println(monday.NewLocaleDetector().Parse("/* Mon, 02 Jan 2006 15:04:05 */", "/* Mon, 02 Nov 2007 17:42:36 */"))
	fmt.Println(time.Parse(".. Mon, 02 Jan 2006 15:04:05 ..", ".. Mon, 02 Nov 2007 17:42:36 .."))
	fmt.Println(monday.NewLocaleDetector().Parse(".. Mon, 02 Jan 2006 15:04:05 ..", ".. Mon, 02 Nov 2007 17:42:36 .."))
}

Outputs:

2007-11-02 17:42:36 +0000 UTC <nil>
0001-01-01 00:00:00 +0000 UTC parsing time "/* Mon, 02 Nov 2007 17:42:36 */"'/* Mon, 02 Nov 2007 17:42:36 */' not matches to '/* Mon, 02 Jan 2006 15:04:05 */' last error position = 0

2007-11-02 17:42:36 +0000 UTC <nil>
2007-11-02 17:42:36 +0000 UTC <nil>
@arran4
Copy link
Author

arran4 commented Feb 16, 2023

bufio.Scanner is more appropriate (and what I have used in similar cases) but requires writing your own identifier for the lexer

@sw360cab
Copy link

@arran4 is it possible that I am encountering the same pseudo issue?

With this example code:

import (
	"fmt"
	"time"
	"github.com/goodsign/monday"
)


func main () {
	var (
		timeLocaleDetector  *monday.LocaleDetector = monday.NewLocaleDetector()
		parsedStartDatetime time.Time
		dateLayout          string = "2 Jan 2006 15:04"
		currentDate         string = "19 May 2024 09:00"
	)

	parsedStartDatetime, _ = timeLocaleDetector.Parse(
		dateLayout,
		currentDate)
	fmt.Println(parsedStartDatetime)
}

The output is the following

<input>:1:13: invalid digit '9' in octal literal
2024-05-19 09:00:00 +0000 UTC

It appears more as a warning, because the datetime is parsed smootly and the Parse method of monday is not returning any error at all.

@arran4
Copy link
Author

arran4 commented May 18, 2024

Yep looks like it, I am not sure if my PR addresses this or not or other things but try the version in that to see if it's any better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants