Skip to content

Commit 4c3f83a

Browse files
authored
Merge pull request #17 from MishkatIT/copilot/run-update-problem-solving-stats
Fix date display and timezone consistency for workflow stats updates
2 parents 88df065 + eeb57fd commit 4c3f83a

4 files changed

Lines changed: 20 additions & 10 deletions

File tree

.github/workflows/update-stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
steps:
1616
- name: Random delay (0-7 minutes)
1717
run: |
18-
RANDOM_SECONDS=$((RANDOM % 1))
18+
RANDOM_SECONDS=$((RANDOM % 420))
1919
echo "Waiting for $RANDOM_SECONDS seconds to randomize execution time..."
2020
sleep $RANDOM_SECONDS
2121

manual_update.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import json
88
import os
9-
from datetime import datetime
9+
from datetime import datetime, timezone, timedelta
1010

1111

1212
def get_manual_stats():
@@ -59,7 +59,9 @@ def get_manual_stats():
5959

6060
def save_last_known_counts(stats):
6161
"""Save the manually entered statistics as last known counts."""
62-
current_date = datetime.now().strftime('%Y-%m-%d')
62+
# Use BDT timezone (UTC+6) for consistency
63+
bdt_tz = timezone(timedelta(hours=6))
64+
current_date = datetime.now(bdt_tz).strftime('%Y-%m-%d')
6365

6466
# Load existing data
6567
last_known = {'counts': {}, 'dates': {}, 'modes': {}}
@@ -129,7 +131,8 @@ def main():
129131
success = update_readme.update_readme(stats, last_known_info=last_known_info, update_source='manual')
130132
if success:
131133
print("\n✓ README.md has been updated successfully!")
132-
print(f" Last updated: {datetime.now().strftime('%d %B %Y')}")
134+
bdt_tz = timezone(timedelta(hours=6))
135+
print(f" Last updated: {datetime.now(bdt_tz).strftime('%d %B %Y')}")
133136
else:
134137
print("\n✗ Failed to update README.md")
135138
else:

update_readme.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,16 +273,21 @@ def update_readme(stats, last_known_info=None, update_source=None):
273273
percentage = calculate_percentage(count_effective, total)
274274

275275
# Pick date to display:
276-
# - If freshly fetched with 'automatic' mode: use current date
276+
# - If freshly fetched today (date matches today): use current date
277277
# - Otherwise: use last-known date (for manual updates or cached data)
278278
platform_mode = last_known_modes.get(platform, 'automatic')
279+
raw_date = last_known_dates.get(platform)
279280

280-
if platform in stats and stats[platform] is not None and platform_mode == 'automatic':
281-
# Freshly fetched automatically today - use current date
281+
# Check if data was freshly fetched today by comparing dates
282+
is_fresh_today = (platform in stats and
283+
stats[platform] is not None and
284+
raw_date == today_iso)
285+
286+
if is_fresh_today:
287+
# Freshly fetched today - use current date
282288
date_str = current_date
283289
else:
284290
# Using cached/manual value - show the cached date
285-
raw_date = last_known_dates.get(platform)
286291
if raw_date:
287292
date_str = _format_human_date(raw_date)
288293
else:

update_stats.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import os
3535
from urllib.request import urlopen, Request
3636
from urllib.error import URLError, HTTPError
37-
from datetime import datetime
37+
from datetime import datetime, timezone, timedelta
3838
from bs4 import BeautifulSoup
3939

4040

@@ -94,7 +94,9 @@ def _update_last_known(self, platform, count, mode=None):
9494
self.last_known_counts['modes'] = {}
9595

9696
self.last_known_counts['counts'][platform] = count
97-
self.last_known_counts['dates'][platform] = datetime.now().strftime('%Y-%m-%d')
97+
# Use BDT timezone (UTC+6) for consistency with update_readme.py
98+
bdt_tz = timezone(timedelta(hours=6))
99+
self.last_known_counts['dates'][platform] = datetime.now(bdt_tz).strftime('%Y-%m-%d')
98100

99101
# Update the mode only if it is different from the existing one
100102
if mode is not None and self.last_known_counts['modes'].get(platform) != mode:

0 commit comments

Comments
 (0)