mirror of
https://github.com/neovim/neovim.git
synced 2024-12-19 10:45:16 -07:00
fix(msgpack#strptime): use calendar.timegm to get seconds since epoch
datetime.datetime.timestamp does not exist on Windows and
datetime.datetiem.strftime('%s') is not supported, since '%s' is a POSIX
format. Instead, use the recommended `calendar.timegm(obj.utctimetuple())`.
(cherry picked from commit fb14e2a8d6
)
This commit is contained in:
parent
6c6ce6894a
commit
1af25791d5
@ -56,6 +56,7 @@ function s:msgpack_init_python() abort
|
||||
\. " time = datetime.datetime.fromtimestamp(timestamp)\n"
|
||||
\. " return time.strftime(fmt)\n"
|
||||
\. "def shada_dict_strptime():\n"
|
||||
\. " import calendar\n"
|
||||
\. " import datetime\n"
|
||||
\. " import vim\n"
|
||||
\. " fmt = vim.eval('a:format')\n"
|
||||
@ -64,7 +65,10 @@ function s:msgpack_init_python() abort
|
||||
\. " try:\n"
|
||||
\. " timestamp = int(timestamp.timestamp())\n"
|
||||
\. " except:\n"
|
||||
\. " timestamp = int(timestamp.strftime('%s'))\n"
|
||||
\. " try:\n"
|
||||
\. " timestamp = int(timestamp.strftime('%s'))\n"
|
||||
\. " except:\n"
|
||||
\. " timestamp = calendar.timegm(timestamp.utctimetuple())\n"
|
||||
\. " if timestamp > 2 ** 31:\n"
|
||||
\. " tsabs = abs(timestamp)\n"
|
||||
\. " return ('{\"_TYPE\": v:msgpack_types.integer,'\n"
|
||||
|
Loading…
Reference in New Issue
Block a user