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

Fix time.strftime("%p") #1729

Open
kengoon opened this issue Aug 17, 2024 · 0 comments
Open

Fix time.strftime("%p") #1729

kengoon opened this issue Aug 17, 2024 · 0 comments

Comments

@kengoon
Copy link

kengoon commented Aug 17, 2024

The below code does not work properly on other platforms except android

def _get_data(self):
try:
if time.strftime("%p"):
result = datetime.datetime.strptime(
f"{int(self.hour):02d}:{int(self.minute):02d} {self.am_pm}",
"%I:%M %p",
).time()
else:
result = datetime.datetime.strptime(
f"{int(self.hour):02d}:{int(self.minute):02d}",
"%I:%M",
).time()
return result
except ValueError:
return None # hour is zero

The reason is simply because materialyoucolor-python which KivyMD depends on has an exception with pyjnius that was not handled properly, thereby messing up with time.strftime("%p"). A fix for that is already on the way. So when fix is merged, the _get_data method should be updated to something like this

def _get_data(self):
        result = datetime.datetime.strptime(
            f"{int(self.hour):02d}:{int(self.minute):02d} {self.am_pm}",
            "%I:%M %p",
        ).time()
        return result
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

1 participant