Title: Storage: mtime of downloaded file is incorrect by UTC offset · Issue #4 · googleapis/python-storage · GitHub
Open Graph Title: Storage: mtime of downloaded file is incorrect by UTC offset · Issue #4 · googleapis/python-storage
X Title: Storage: mtime of downloaded file is incorrect by UTC offset · Issue #4 · googleapis/python-storage
Description: Google Cloud Storage v1.25.0 Python 3.7.3 OS: OSX & Win7 Issue: If I upload a file to Google Cloud Storage and then immediately download it, the mtime is incorrect - for me, I'm in EST, so I'm 5 hours behind UTC. That's the exact timedel...
Open Graph Description: Google Cloud Storage v1.25.0 Python 3.7.3 OS: OSX & Win7 Issue: If I upload a file to Google Cloud Storage and then immediately download it, the mtime is incorrect - for me, I'm in EST, so I'm 5 ho...
X Description: Google Cloud Storage v1.25.0 Python 3.7.3 OS: OSX & Win7 Issue: If I upload a file to Google Cloud Storage and then immediately download it, the mtime is incorrect - for me, I'm in EST, so ...
Opengraph URL: https://github.com/googleapis/python-storage/issues/4
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Storage: mtime of downloaded file is incorrect by UTC offset","articleBody":"Google Cloud Storage v1.25.0\r\nPython 3.7.3\r\nOS: OSX \u0026 Win7\r\n\r\nIssue: If I upload a file to Google Cloud Storage and then immediately download it, the mtime is incorrect - for me, I'm in EST, so I'm 5 hours behind UTC. That's the exact timedelta that occurs between the file's original mtime and the recorded mtime after the file is downloaded.\r\n\r\nHere's an example screenshot:\r\n\r\nThe original file mtime in Google Cloud Storage is 1/23/20 9:04 PM (which is correct from the file I uploaded), but when I download the file, the mtime becomes 1/24/20 2:04 AM, which is 5 hours ahead of what is supposed to be (the UTC offset from my timezone).\r\n\r\nThe issue is here in `blob.download_to_filename`:\r\n```\r\nupdated = self.updated\r\nif updated is not None:\r\n mtime = time.mktime(updated.timetuple())\r\n os.utime(file_obj.name, (mtime, mtime))\r\n```\r\nIn my example, `updated` is the timezone-aware datetime corresponding to `2020-01-24 02:04:11.184000+00:00` (it has `tzinfo==UTC`). The `updated.timetuple()` is\r\n```\r\ntime.struct_time(tm_year=2020, tm_mon=1, tm_mday=24, tm_hour=2, tm_min=4, tm_sec=9, tm_wday=4, tm_yday=24, tm_isdst=0)\r\n```\r\n\r\nThe problem, I believe, is that the timetuple doesn't know this is a UTC date, nor did it convert to my timezone. The docs of `mktime` note, \"Its argument is the struct_time or full 9-tuple (since the dst flag is needed; use -1 as the dst flag if it is unknown) which expresses the time in local time, not UTC.\" Perhaps, we should do this instead:\r\n```\r\nif updated is not None:\r\n mtime = updated.timestamp() # For Python3, not sure of the Python2 version\r\n os.utime(file_obj.name, (mtime, mtime))\r\n```\r\n\r\nThe `timestamp()` function accounts for the timezone information in the datetime object.\r\nI've just been doing this manually in my code after downloading a file because my application is sensitive to mtimes, and it seems to fix the issue.","author":{"url":"https://github.com/mcsimps2","@type":"Person","name":"mcsimps2"},"datePublished":"2020-01-28T02:54:43.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/4/python-storage/issues/4"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:bcf33e0b-cb64-1beb-4e41-515b9757ac5c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E032:69662:213A714:2D9D7FB:6A4ED81D |
| html-safe-nonce | c69b6406127ebff5ad831d47491052313446849de84892c3ea724fec8498094b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMDMyOjY5NjYyOjIxM0E3MTQ6MkQ5RDdGQjo2QTRFRDgxRCIsInZpc2l0b3JfaWQiOiI1NzYwNzc0NjY5MTA1MTMxODEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 220282589138d1a4def4410302ee21eb595e60683c4e1c8167eae805574720fc |
| hovercard-subject-tag | issue:558423137 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/googleapis/python-storage/4/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3271766e66439a65353aa00b67586be1fc0eea7334e03741208aa7ea305bbae3/googleapis/python-storage/issues/4 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3271766e66439a65353aa00b67586be1fc0eea7334e03741208aa7ea305bbae3/googleapis/python-storage/issues/4 |
| og:image:alt | Google Cloud Storage v1.25.0 Python 3.7.3 OS: OSX & Win7 Issue: If I upload a file to Google Cloud Storage and then immediately download it, the mtime is incorrect - for me, I'm in EST, so I'm 5 ho... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mcsimps2 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 41b6ab3ba6d20a71766ac245b5a4a94c6fc672a9cd4da7d44c1b33ab8bf6a21c |
| turbo-cache-control | no-preview |
| go-import | github.com/googleapis/python-storage git https://github.com/googleapis/python-storage.git |
| octolytics-dimension-user_id | 16785467 |
| octolytics-dimension-user_login | googleapis |
| octolytics-dimension-repository_id | 226992639 |
| octolytics-dimension-repository_nwo | googleapis/python-storage |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 226992639 |
| octolytics-dimension-repository_network_root_nwo | googleapis/python-storage |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | c37fe3e3f5f306900bd5b6bee97463f66c938b2c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width