Comment 2 for bug 1911469

Revision history for this message
Cubic PPA (cubic-wizard) wrote :

Perhaps the best option is to be very explicit about the time format.

Instead to trying to intrepret the time format string based on locale, we should define it to be the same string for all locales. The drawback obviously is that date and time will not be displayed in a localized manner, which was preferable.

PEP does provides guidance in favor of this explicit approach: "In the face of ambiguity, refuse the temptation to guess." (https://www.python.org/dev/peps/pep-0020)

This approach will work well for new projects in all locales. However, for existing projects the create_date in the cubic.conf file will have the old format, and this will result in the same parsing issue in certain locales such as nb_NO.UTF-8. We could opt to simply not parse the create_date, since it never changes once a project is created. The modify_date is always overwritten and does not need to be parsed.

A reasonable format to use is "YYYY-MM-DD HH:MM" with HH in 24 hr format; we probably don't need to display seconds.

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    > import locale
    > locale.setlocale(locale.LC_ALL, 'nb_NO.UTF-8')
      'nb_NO.UTF-8'

    > import datetime
    > time_stamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M')
    > time_stamp
      '2021-01-24 22:36'

    > import time
    > struct_time = time.strptime(time_stamp, '%Y-%m-%d %H:%M')

    > time.strftime('%Y', struct_time)
      '2021'

    > time.strftime('%m', struct_time)
      '01'

    > time.strftime('%d', struct_time)
      '24'

    > time.strftime('%H:%M%S', struct_time)
      '22:3600'

    > time.strftime('%Y-%m-%d %H:%M', struct_time)
      '2021-01-24 22:36'
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -