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

time: d,c,dd,ddd,dddd pattern support for parse_format() #22003

Merged
merged 7 commits into from
Aug 9, 2024

Conversation

jeffangelion
Copy link
Contributor

Allow weekday name to be parseable (doesn't affect Time struct)

vlib/time/time_test.v Outdated Show resolved Hide resolved
vlib/time/time_test.v Outdated Show resolved Hide resolved
@JalonSolov
Copy link
Contributor

long_days.index(weekday)

should be

long_days[weekday]

@jeffangelion
Copy link
Contributor Author

@JalonSolov yeah you're right

already changed fn output from !int to !string (don't see much difference since fn result is always ignoring)

@JalonSolov
Copy link
Contributor

One possibility is that you declared the function as returning a Result, but there are no error returns. If either of the if statements "fail" (as in the check doesn't let the code go into the body of the if), you could wind up with no answer at all, which should probably be an error...

@spytheman
Copy link
Member

One possibility is that you declared the function as returning a Result, but there are no error returns. If either of the if statements "fail" (as in the check doesn't let the code go into the body of the if), you could wind up with no answer at all, which should probably be an error...

The function in question ends with:
return error_invalid_time(0, 'invalid weekday, at: ${p.current_pos_datetime}')

If I comment that out, I get:
image

I think it works fine.

The only usage of that function is currently this one:

            'dddd' {
                p.must_be_valid_week_day() or { return err }
            }

@JalonSolov
Copy link
Contributor

And of course, that can be shortened to

            'dddd' {
                p.must_be_valid_week_day()!
            }

@jeffangelion
Copy link
Contributor Author

And of course, that can be shortened to

IMHO writing functions for handling weekdays is overengineering since we're dropping them right away

@medvednikov medvednikov merged commit c0bb960 into vlang:master Aug 9, 2024
61 checks passed
spytheman added a commit to martinskou/v that referenced this pull request Aug 11, 2024
* master:
  flag: add optional value description to string parameters (vlang#22024)
  fmt: fix alignment of struct init fields (vlang#22025)
  cgen: fix selector with interface var (vlang#22006)
  checker: add a deprecation warning for `const ()` groups (an error after 2025-01-01) (vlang#22019)
  v2: fix a notice for `v cmd/v2/v2.v`
  tools: reduce number of os/fs calls done by `v where`; ignore tests/ folders
  tools: make `v where` ignore .git/ folders (they contain binary files); let `-dir .` work recursively, so that `-dir vlib` works
  fmt: cleanup fields alignment (vlang#22018)
  veb: change example description, to avoid repetitive wording (ease debugging of issue#22017)
  all: allow multi return as fn argument (vlang#21991)
  examples: change // to blank line in 2048.v too, after 793b66d
  all: change single blank comment to blank line (vlang#22016)
  scanner: guard against scanner panic, discovered by fuzzing in PR#22016
  time: `d`,`c`,`dd`,`ddd`,`dddd` pattern support for parse_format() (vlang#22003)
  ast, parser, fmt: cleanup fmt of struct fields with empty line (vlang#22014)
  ast, parser, fmt: fix fmt of enum fields with empty line (vlang#22015)
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

Successfully merging this pull request may close these issues.

4 participants