Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateTime: use strftime('%H %M', 0) on Windows #578

Merged
merged 6 commits into from
May 18, 2018
Merged

DateTime: use strftime('%H %M', 0) on Windows #578

merged 6 commits into from
May 18, 2018

Conversation

mattn
Copy link
Member

@mattn mattn commented Apr 30, 2018

Current implementation on Windows use Windows registory since %z on Windows return '東京 (標準時)'. But it is bit slow. strftime('%c', 0) must be epoch based on 1970/1/1 0:0:0, so hours and minutes
must be time offset.

let item = split(strftime('%c', 0), ' ')
let hms = map(split(item[1], '[^0-9]'), 'str2nr(v:val)')
let tz_sec = hms[0] * 60 * 60 + hms[1] * 60
if item[0] !~ '^1970'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[vint] reported by reviewdog 🐶
Use robust operators !~# or !~? instead of !~ (see Google VimScript Style Guide (Matching))

let hms = map(split(item[1], '[^0-9]'), 'str2nr(v:val)')
let tz_sec = hms[0] * 60 * 60 + hms[1] * 60
if item[0] !~ '^1970'
return printf('-%02d%02d', hms[0], hms[1])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong.

return s:win_tz
let item = split(strftime('%c', 0), ' ')
let hms = map(split(item[1], '[^0-9]'), 'str2nr(v:val)')
let tz_sec = hms[0] * 60 * 60 + hms[1] * 60

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[vimlint] reported by reviewdog 🐶
EVL102: unused variable l:tz_sec

let item = split(strftime('%c', 0), ' ')
let hms = map(split(item[1], '[^0-9]'), 'str2nr(v:val)')
let tz_sec = hms[0] * 60 * 60 + hms[1] * 60
if item[0] !~ '^1970'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[vint] reported by reviewdog 🐶
Use robust operators !~# or !~? instead of !~ (see Google VimScript Style Guide (Matching))

let item = split(strftime('%c', 0), ' ')
let hms = map(split(item[1], '[^0-9]'), 'str2nr(v:val)')
let tz_sec = hms[0] * 60 * 60 + hms[1] * 60
if item[0] !~ '^1970'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[vint] reported by reviewdog 🐶
Use robust operators !~# or !~? instead of !~ (see Google VimScript Style Guide (Matching))

let item = split(strftime('%c', 0), ' ')
let hms = map(split(item[1], '[^0-9]'), 'str2nr(v:val)')
let tz_sec = hms[0] * 60 * 60 + hms[1] * 60
if item[0] !~ '^1970'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[vint] reported by reviewdog 🐶
Use robust operators !~# or !~? instead of !~ (see Google VimScript Style Guide (Matching))

@thinca
Copy link
Member

thinca commented May 1, 2018

%c は表現がロケール依存なので一意にパースは不可能な気がします。%Y %H %M を使ってみてはどうでしょう?

Copy link
Member

@thinca thinca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 つ目のコミットメッセージの DateTime: Datetime: になってしまっているので直してほしいです。ひとまとめにしてもらっちゃっても大丈夫です。

let l:tz_sec = 60 * 60 * 24 - l:tz_sec
return printf('-%02d%02d', l:tz_sec / 60 / 60, (l:tz_sec / 60) % 60)
endif
return printf('+%02d%02d', l:hms[0], l:hms[1])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vital では l: なしに統一しているので合わせてもらえると 🙏

@thinca thinca changed the title Datetime: use strftime('%c', 0) on Windows Datetime: use strftime('%H %M', 0) on Windows May 1, 2018
let hm = map(split(strftime('%H %M', 0), ' '), 'str2nr(v:val)')
if str2nr(strftime('%Y', 0)) != 1970
let tz_sec = hm[0] * s:NUM_SECONDS * s:NUM_MINUTES + hm[1] * s:NUM_SECONDS
let tz_sec = s:NUM_SECONDS * s:NUM_MINUTES * s:NUM_HOURS - tz_sec
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s:SECONDS_OF_DAY が便利そう。

return s:win_tz
let hm = map(split(strftime('%H %M', 0), ' '), 'str2nr(v:val)')
if str2nr(strftime('%Y', 0)) != 1970
let tz_sec = hm[0] * s:NUM_SECONDS * s:NUM_MINUTES + hm[1] * s:NUM_SECONDS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s:SECONDS_OF_HOUR が便利な予感。

if str2nr(strftime('%Y', 0)) != 1970
let tz_sec = hm[0] * s:NUM_SECONDS * s:NUM_MINUTES + hm[1] * s:NUM_SECONDS
let tz_sec = s:NUM_SECONDS * s:NUM_MINUTES * s:NUM_HOURS - tz_sec
return printf('-%02d%02d', tz_sec / s:NUM_SECONDS / s:NUM_MINUTES, (tz_sec / s:NUM_SECONDS) % s:NUM_MINUTES)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

実はここも hour の方は tz_sec / s:SECONDS_OF_HOUR で行ける可能性。

@thinca
Copy link
Member

thinca commented May 1, 2018

テスト通った 🎉

@thinca
Copy link
Member

thinca commented May 1, 2018

あ、Approve したけどコミットメッセージがまだ直ってませんでした。

Datetime: use strftime('%c', 0) on Windows

DateTime

@mattn
Copy link
Member Author

mattn commented May 1, 2018

squash してコミットメッセージ変えた方が良さそうです?

@mattn
Copy link
Member Author

mattn commented May 1, 2018

あー、最初のコミットの事でしたか。

mattn added 6 commits May 1, 2018 13:42
Current implementation on Windows use Windows registory since %z on Windows
return '東京 (標準時)'. But it is bit slow.
strftime('%c', 0) must be epoch based on 1970/1/1 0:0:0, so hours and minutes
must be time offset.
@thinca
Copy link
Member

thinca commented May 1, 2018

ありがとうございます! 🙏

@thinca thinca changed the title Datetime: use strftime('%H %M', 0) on Windows DateTime: use strftime('%H %M', 0) on Windows May 1, 2018
Copy link
Member

@ujihisa ujihisa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🍣

ついでにPreludeも依存から消せるかな、と思って全体みたらめっちゃ使ってた。
とりあえずこのpullreqはもうマージしちゃいたいですね!

@thinca thinca merged commit a8773a3 into master May 18, 2018
@thinca thinca deleted the use-zero branch May 18, 2018 02:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants