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

Highlight improvement about `%d` in the datetime format #122

Open
liangshan opened this issue Jan 9, 2018 · 1 comment
Open

Highlight improvement about `%d` in the datetime format #122

liangshan opened this issue Jan 9, 2018 · 1 comment

Comments

@liangshan
Copy link

@liangshan liangshan commented Jan 9, 2018

  • Editor name and version: VSCode 1.19
  • Platform: MacOS
  • Color scheme: Dark+
  • MagicPython version: Default
  • A sreenshot:
    issue

When %d is part of datetime format string, i think it should not be highlighted.

@vpetrovykh
Copy link
Member

@vpetrovykh vpetrovykh commented Jul 19, 2018

As has been mentioned in similar issues already, it is not possible to always correctly infer that a particular string is a "datetime format" string. E.g.:

dt_format = 'The date is: %Y%m%d'
# format output
dt_out = datetime.strftime(datetime.now(), dt_format)

# parse input
my_datetime = datetime.strptime('The date is: 20180719', dt_format)

If the code is yours, you can choose to use r'%Y%m%d' or R'%Y%m%d' to avoid format highlighting. Note that r'...' will be highlighted as if it were a regex string, while R'...' is a raw string with no frills.

Additionally, the issue #106 has a proposal that would allow configuring the color scheme to hide %-formatting completely (implemented and being reviewed as of this writing).

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

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.