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

Add configurable first day of the week #294

Closed
wants to merge 2 commits into from

Conversation

sandrobonazzola
Copy link
Contributor

Fixes #293

Add configurable first day of the week:

[general]
# set first day of week on Sunday
week = 6

Signed-off-by: Sandro Bonazzola [email protected]

@kwk
Copy link
Collaborator

kwk commented Feb 7, 2023

@sandrobonazzola thank you for this PR. Can you please add tests to it?

@sandrobonazzola
Copy link
Contributor Author

@sandrobonazzola thank you for this PR. Can you please add tests to it?

@kwk done

Copy link
Collaborator

@kwk kwk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for adding the tests.

@@ -267,7 +281,7 @@ def test_get_token_plain_different_name(self):
token = str(uuid4())
config = {"mytoken": token}
self.assertIsNone(get_token(config))
self.assertEqual(get_token(config, token_key="mytoken"), token)
self.assertEqual(get_token(config, token_key="mytoken"), token) # nosec
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this slipped in from your other PR #297 .

Suggested change
self.assertEqual(get_token(config, token_key="mytoken"), token) # nosec
self.assertEqual(get_token(config, token_key="mytoken"), token)

@@ -278,7 +292,7 @@ def test_get_token_file(self):

def test_get_token_file_empty(self):
""" Test getting a token from a file with just whitespace. """
token_in_file = " "
token_in_file = " " # nosec
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this slipped in from your other PR #297 .

Suggested change
token_in_file = " " # nosec
token_in_file = " "

@@ -296,7 +310,7 @@ def test_get_token_file_different_name(self):
token_in_file = str(uuid4())
with self.get_token_as_file(token_in_file) as filename:
config = {"mytoken_file": filename}
self.assertEqual(
self.assertEqual( # nosec
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this slipped in from your other PR #297 .

Suggested change
self.assertEqual( # nosec
self.assertEqual(

@@ -125,6 +124,17 @@ def quarter(self):
f"Invalid quarter start '{month}', should be integer.")
return month

@property
def week(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this called week when it is really the first day of the week?

Suggested change
def week(self):
def first_day_of_week(self) -> int:

""" The first day of the week, 0 (Monday) by default"""
week = self.parser.get("general", "week", fallback=0)
try:
week = int(week) % 7
Copy link
Collaborator

@kwk kwk Feb 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to have a string in the config rather than an int. Transferring to an int internally is fine though. I think of something like this:

#!/bin/env python

WEEKDAYS = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
config_first_day_of_week = "WednES"

# Default first day of the week:
first_day_of_week = 0

# This should allow anything from: "Mon", "mon", "mond", "monda", "monday", "MON",
# but not "mo", "MO" or "M" because it is too short.
if len(config_first_day_of_week) > 3:
    for idx, weekday in enumerate(WEEKDAYS):
        if weekday.lower().startswith(config_first_day_of_week.lower()):
            first_day_of_week = idx

print(first_day_of_week)

@sandrobonazzola
Copy link
Contributor Author

Sorry, no time to keep working on this, abandoning

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