This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: android: test_strptime fails
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: xdegaye Nosy List: Alex.Willmer, belopolsky, lemburg, python-dev, serhiy.storchaka, xdegaye
Priority: normal Keywords: patch

Created on 2016-05-03 14:11 by xdegaye, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test_output.txt xdegaye, 2016-05-03 14:11 test results
exclude_ymd.patch xdegaye, 2016-11-09 09:52 review
exclude_ymd_2.patch xdegaye, 2016-11-11 16:22 review
exclude_ymd_3.patch xdegaye, 2016-11-12 08:33 Fixes the tuple. review
Messages (16)
msg264729 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2016-05-03 14:11
test_strptime fails on an android emulator running an x86 system image at API level 21.

See the attached test_output.txt file.
msg264760 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-05-03 19:53
What is the output of following code?

import datetime
for i in range(1, 10):
    print(datetime.date(1905, 1, i).strftime('%Y %U %w   %G %V %u'))
msg264761 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2016-05-03 20:02
root@generic_x86:/data/local/tmp # python
Python 3.6.0a0 (default:f4c6dab59cd8+, May  3 2016, 21:59:47) 
[GCC 4.9 20140827 (prerelease)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> for i in range(1, 10):
...   print(datetime.date(1905, 1, i).strftime('%Y %U %w   %G %V %u'))
... 
1905 01 0   1904 53 7
1905 01 1   1905 01 1
1905 01 2   1905 01 2
1905 01 3   1905 01 3
1905 01 4   1905 01 4
1905 01 5   1905 01 5
1905 01 6   1905 01 6
1905 02 0   1905 01 7
1905 02 1   1905 02 1
>>>
msg264762 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-05-03 20:13
Thanks. And what is the output of following code?

for i in range(25, 32):
    print(datetime.date(1904, 12, i).strftime('%Y %U %w   %G %V %u'))
msg264763 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2016-05-03 20:21
>>> for i in range(25, 32):
...   print(datetime.date(1904, 12, i).strftime('%Y %U %w   %G %V %u'))
... 
1904 52 0   1904 51 7
1904 52 1   1904 52 1
1904 52 2   1904 52 2
1904 52 3   1904 52 3
1904 52 4   1904 52 4
1904 52 5   1904 52 5
1904 52 6   1904 52 6
>>>
msg264765 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-05-03 20:34
Thus there is a gap between 1904-12-31 and 1905-1-1. This is a bug in strftime() on Android.
msg264768 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2016-05-03 21:08
GNU libc says:

     ‘%V’
          The ISO 8601:1988 week number as a decimal number (range ‘01’
          through ‘53’).  ISO weeks start with Monday and end with
          Sunday.  Week ‘01’ of a year is the first week which has the
          majority of its days in that year; this is equivalent to the
          week containing the year’s first Thursday, and it is also
          equivalent to the week containing January 4.  Week ‘01’ of a
          year can contain days from the previous year.  The week before
          week ‘01’ of a year is the last week (‘52’ or ‘53’) of the
          previous year even if it contains days from the new year.

          This format was first standardized by POSIX.2-1992 and by
          ISO C99.


So on 1905-1-1, %V should be 52 instead of 53 as printed by android; is this the only bug ?

A pretty good test to find such a mistake.
msg264769 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-05-03 21:27
There is other bug at the last week of a year:

import datetime
for i in range(25, 32):
    print(datetime.date(1906, 12, i).strftime('%Y %U %w   %G %V %u'))

for i in range(1, 10):
    print(datetime.date(1907, 1, i).strftime('%Y %U %w   %G %V %u'))
msg264786 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2016-05-04 07:29
Here is the result of running on android:

<script>
import datetime

for y in (1904, 1906, 2008, 1917):
    for i in range(25, 32):
        print(datetime.date(y, 12, i).strftime('%Y %U %w   %G %V %u'))
    print()

    for i in range(1, 10):
          print(datetime.date(y + 1, 1, i).strftime('%Y %U %w   %G %V %u'))
    print('=====================')
<script>


root@generic_x86:/data/local/tmp # python strftime.py
1904 52 0   1904 51 7
1904 52 1   1904 52 1
1904 52 2   1904 52 2
1904 52 3   1904 52 3
1904 52 4   1904 52 4
1904 52 5   1904 52 5
1904 52 6   1904 52 6

1905 01 0   1904 53 7
1905 01 1   1905 01 1
1905 01 2   1905 01 2
1905 01 3   1905 01 3
1905 01 4   1905 01 4
1905 01 5   1905 01 5
1905 01 6   1905 01 6
1905 02 0   1905 01 7
1905 02 1   1905 02 1
=====================
1906 51 2   1906 52 2
1906 51 3   1906 52 3
1906 51 4   1906 52 4
1906 51 5   1906 52 5
1906 51 6   1906 52 6
1906 52 0   1906 52 7
1906 52 1   1907 53 1

1907 00 2   1907 01 2
1907 00 3   1907 01 3
1907 00 4   1907 01 4
1907 00 5   1907 01 5
1907 00 6   1907 01 6
1907 01 0   1907 01 7
1907 01 1   1907 02 1
1907 01 2   1907 02 2
1907 01 3   1907 02 3
=====================
2008 51 4   2008 52 4
2008 51 5   2008 52 5
2008 51 6   2008 52 6
2008 52 0   2008 52 7
2008 52 1   2009 53 1
2008 52 2   2009 53 2
2008 52 3   2009 53 3

2009 00 4   2009 01 4
2009 00 5   2009 01 5
2009 00 6   2009 01 6
2009 01 0   2009 01 7
2009 01 1   2009 02 1
2009 01 2   2009 02 2
2009 01 3   2009 02 3
2009 01 4   2009 02 4
2009 01 5   2009 02 5
=====================
1917 51 2   1917 52 2
1917 51 3   1917 52 3
1917 51 4   1917 52 4
1917 51 5   1917 52 5
1917 51 6   1917 52 6
1917 52 0   1917 52 7
1917 52 1   1918 53 1

1918 00 2   1918 01 2
1918 00 3   1918 01 3
1918 00 4   1918 01 4
1918 00 5   1918 01 5
1918 00 6   1918 01 6
1918 01 0   1918 01 7
1918 01 1   1918 02 1
1918 01 2   1918 02 2
1918 01 3   1918 02 3
=====================
msg264790 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-05-04 08:01
1904 52 6   1904 52 6
1905 01 0   1904 53 7
                 ^^

1906 52 0   1906 52 7
1906 52 1   1907 53 1
            ^^^^

strftime() on Android incorrectly formats %V or %G for the last or the first incomplete week in a year.
msg280388 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2016-11-09 09:52
Patch attached.
msg280389 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2016-11-09 10:05
Entered new issue https://code.google.com/p/android/issues/detail?id=227388 on the AOSP issue tracker.
msg280594 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2016-11-11 16:22
New patch following Serhiy comments.
msg280644 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-11-12 09:00
exclude_ymd_3.patch LGTM.
msg280647 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2016-11-12 09:16
Thanks Serhiy for your help with this issue.
I will push this patch with the other Android patches after 3.6 is released.
msg280864 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-11-15 16:26
New changeset 3c6e5f83d235 by Xavier de Gaye in branch '3.6':
Issue #26929: Skip some test_strptime tests failing on Android that
https://hg.python.org/cpython/rev/3c6e5f83d235

New changeset 91e0cf7f8e30 by Xavier de Gaye in branch 'default':
Issue #26929: Merge 3.6
https://hg.python.org/cpython/rev/91e0cf7f8e30
History
Date User Action Args
2022-04-11 14:58:30adminsetgithub: 71116
2016-11-15 18:52:40xdegayesetstatus: open -> closed
resolution: fixed
stage: commit review -> resolved
2016-11-15 16:26:48python-devsetnosy: + python-dev
messages: + msg280864
2016-11-12 09:16:50xdegayesetmessages: + msg280647
2016-11-12 09:00:52serhiy.storchakasetmessages: + msg280644
stage: patch review -> commit review
2016-11-12 08:33:38xdegayesetfiles: + exclude_ymd_3.patch
2016-11-11 16:22:38xdegayesetfiles: + exclude_ymd_2.patch

messages: + msg280594
2016-11-09 10:05:10xdegayesetmessages: + msg280389
2016-11-09 09:52:15xdegayesetfiles: + exclude_ymd.patch

assignee: xdegaye
components: - Cross-Build
versions: + Python 3.7
keywords: + patch
messages: + msg280388
stage: patch review
2016-05-21 07:06:39xdegayelinkissue26865 dependencies
2016-05-04 08:01:48serhiy.storchakasetmessages: + msg264790
2016-05-04 07:29:30xdegayesetmessages: + msg264786
2016-05-03 21:27:26serhiy.storchakasetmessages: + msg264769
2016-05-03 21:08:28xdegayesetmessages: + msg264768
2016-05-03 20:34:23serhiy.storchakasetmessages: + msg264765
2016-05-03 20:21:15xdegayesetmessages: + msg264763
2016-05-03 20:13:14serhiy.storchakasetmessages: + msg264762
2016-05-03 20:02:55xdegayesetmessages: + msg264761
2016-05-03 19:53:12serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg264760
2016-05-03 14:11:51xdegayecreate