athul / waka-readme

Wakatime Weekly Metrics on your Profile Readme.
https://github.com/athul
MIT License
1.56k stars 302 forks source link

fix: Changed to week streak instead for week of the year #8

Closed yozachar closed 4 years ago

yozachar commented 4 years ago

@rajitbanerjee mentions in #7

The Waka Time API returns metrics from the last 7 days from the current date, and not according to weeks of the year.

def this_week():
'''Returns a week's streak'''
month = datetime.date.today().strftime('%B')
week_end = datetime.datetime.today().day - 1
week_start = week_end - 7
return f"Week : {month} {week_start} - {month} {week_end}"

This pull fixes it.

yozachar commented 4 years ago

@athul

Merge branch 'master' of https://github.com/joe733/waka-readme

Why does this commit appear automatically? I amended a commit, is that why it's happening?

rajitbanerjee commented 4 years ago

Thanks for taking a look! But I don't think this will work when the month/year rolls over. For the first 7 days of a month, week_start will be < 0 and week_end will be in the next month. Probably it'll be easiest to just display the full date range like so:

def this_week():
    '''Returns a week's streak'''
    week_end = datetime.datetime.today() - datetime.timedelta(days=1)
    week_start = week_end - datetime.timedelta(days=7)
    return f"Week: {week_start.strftime('%d %B, %Y')} - {week_end.strftime('%d %B, %Y')}"

image

yozachar commented 4 years ago

Thanks for taking a look! But I don't think this will work when the month/year rolls over. For the first 7 days of a month, week_start will be < 0 and week_end will be in the next month. Probably it'll be easiest to just display the full date range like so:

def this_week():
    '''Returns a week's streak'''
    week_end = datetime.datetime.today() - datetime.timedelta(days=1)
    week_start = week_end - datetime.timedelta(days=7)
    return f"Week: {week_start.strftime('%d %B, %Y')} - {week_end.strftime('%d %B, %Y')}"

image

You're right! I missed it 🤦🏻‍♂️.

Fixed it.

athul commented 4 years ago

Thanks @rajitbanerjee and @joe733 for looking on this and the fix. There is mistake on my side too since I was unable to run the API call and verify the week.

Thanks a ton to the both of you 😍