1

I want to know what is the start of the week, but it should be according to a specific time zone or locale.

I can retrieve the datetime of the start of the day like this

now = datetime.now()
weekday = now.weekday()   # 0 if it is Monday
start_of_week = now.replace(day=now.day-weekday)

But if I am in a country where the start of the week is Sunday (for example timezone 'Asia/Tel_Aviv') this won't work.

Is there a way to get the start of the week according to timezone or locale with pytz or any other library?

Kemeia
  • 826
  • 2
  • 9
  • 24
  • https://stackoverflow.com/questions/727471/how-do-i-get-the-first-day-of-the-week-for-the-current-locale-php-l8n – Josh Lee Jun 19 '17 at 13:43

1 Answers1

0

Not that I am aware of.

This information is not in pytz database. It would be available in locale database, but your system probably doesn't have all possible locales installed (on linux systems locale -a shows what is in there). You could in theory install them all and build a converter between a timezone and a locale, and check it from there.

Far too complicated to my taste.

I would just do this manually. There are only so many countries in the world, and most of them use Monday as the first day of week. Just build a dictionary with about 200 entries, you can import the data for example from here: http://chartsbin.com/view/41671

Hannu

Hannu
  • 11,685
  • 4
  • 35
  • 51