mirror of https://github.com/bobwen-dev/htpdate
better adjust method
win32: there's a way to get the perfect command for everybody in every location; linux: wait for a whole second tick before date command;
This commit is contained in:
parent
fe6c91fcc7
commit
c532751be0
|
@ -42,7 +42,7 @@ Done
|
||||||
|
|
||||||
Note: Windows users need to be aware of the date format in their region. Default format(from [dayjs](https://day.js.org/docs/en/display/format)) is `MM-DD-YY`, users in non-U.S. regions may need to customize it with the `-C` parameter, eg:
|
Note: Windows users need to be aware of the date format in their region. Default format(from [dayjs](https://day.js.org/docs/en/display/format)) is `MM-DD-YY`, users in non-U.S. regions may need to customize it with the `-C` parameter, eg:
|
||||||
|
|
||||||
`htpdate -s -C "[time ]HH[:]mm[:]ss[.]SS[ && date ]YY[-]MM[-]DD" github.com`.
|
`htpdate -s -C "[time ]HH:mm:ss.SS[ && date ]YY-MM-DD" github.com`.
|
||||||
|
|
||||||
Query from multiple URLs
|
Query from multiple URLs
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
util = require 'util'
|
util = require 'util'
|
||||||
{ spawn } = require 'child_process'
|
{ spawn } = require 'child_process'
|
||||||
dayjs = require 'dayjs'
|
dayjs = require 'dayjs'
|
||||||
|
delay = require './delay'
|
||||||
dayjs.extend require './dayjs_format_ms'
|
dayjs.extend require './dayjs_format_ms'
|
||||||
platform = require('os').platform()
|
platform = require('os').platform()
|
||||||
|
|
||||||
|
@ -24,17 +25,30 @@ adjust_time = (delta) ->
|
||||||
shell.stdin.write "#{cmd}\n", (p...) ->
|
shell.stdin.write "#{cmd}\n", (p...) ->
|
||||||
await wait_data() if platform in ['win32']
|
await wait_data() if platform in ['win32']
|
||||||
cb p...
|
cb p...
|
||||||
await wait_data() if platform in ['win32']
|
if platform in ['win32']
|
||||||
cmd = dayjs().add(delta, 'ms').format adjust_time.command
|
await wait_data()
|
||||||
|
new_time = dayjs().add(delta, 'ms')
|
||||||
|
cmd = new_time.format adjust_time.command
|
||||||
|
else
|
||||||
|
adjust_time.command = adjust_time.command.replace /ss\.S+/, 'ss'
|
||||||
|
new_time = dayjs().add(delta, 'ms')
|
||||||
|
ms = new_time.get('millisecond')
|
||||||
|
if ms > 0
|
||||||
|
wait_time = 1000 - ms
|
||||||
|
new_time = new_time.add(wait_time, 'ms')
|
||||||
|
delay wait_time
|
||||||
|
cmd = new_time.format adjust_time.command
|
||||||
await input_line cmd
|
await input_line cmd
|
||||||
await input_line 'exit'
|
await input_line 'exit'
|
||||||
|
|
||||||
|
|
||||||
COMMANDS = {
|
COMMANDS = {
|
||||||
win32: '[time ]HH[:]mm[:]ss[.]SS[ && date ]MM[-]DD[-]YY'
|
# FIXME get the perfect win32 command with right format
|
||||||
# FIXME linux command date or timedatectl cannot process the millisecond parts (.SSS)
|
# yes I got it, weird but effective
|
||||||
# we can wait for a whole second tick to solve the problem
|
# reg query "HKEY_CURRENT_USER\Control Panel\International" /v sShortDate
|
||||||
linux: '[date +%FT%T -s ]YYYY[-]MM[-]DDTHH[:]mm[:]ss[.]SSS'
|
# various formats need to be recognized...
|
||||||
|
win32: '[time ]HH:mm:ss.SS[ && date ]MM-DD-YY'
|
||||||
|
linux: '[date -s ]"YYYY-MM-DD HH:mm:ss"'
|
||||||
}
|
}
|
||||||
adjust_time.command = COMMANDS[platform] or COMMANDS.linux
|
adjust_time.command = COMMANDS[platform] or COMMANDS.linux
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
util = require 'util'
|
||||||
|
|
||||||
|
module.exports = util.promisify (ms, cb) ->
|
||||||
|
return cb() if ms <= 0
|
||||||
|
setTimeout cb, ms
|
|
@ -1,6 +1,5 @@
|
||||||
#!/usr/bin/env coffee
|
#!/usr/bin/env coffee
|
||||||
|
|
||||||
util = require 'util'
|
|
||||||
got = require 'got'
|
got = require 'got'
|
||||||
Agent = require 'agentkeepalive'
|
Agent = require 'agentkeepalive'
|
||||||
{ HttpProxyAgent, HttpsProxyAgent } = require('hpagent')
|
{ HttpProxyAgent, HttpsProxyAgent } = require('hpagent')
|
||||||
|
@ -8,6 +7,7 @@ dayjs = require 'dayjs'
|
||||||
info = require './package.json'
|
info = require './package.json'
|
||||||
median = require './median'
|
median = require './median'
|
||||||
adjust_time = require './adjust_time'
|
adjust_time = require './adjust_time'
|
||||||
|
delay = require './delay'
|
||||||
|
|
||||||
|
|
||||||
argv = require('./argv') {
|
argv = require('./argv') {
|
||||||
|
@ -177,11 +177,6 @@ get_time_delta = (url) ->
|
||||||
delta
|
delta
|
||||||
|
|
||||||
|
|
||||||
delay = util.promisify (ms, cb) ->
|
|
||||||
return cb() if ms <= 0
|
|
||||||
setTimeout cb, ms
|
|
||||||
|
|
||||||
|
|
||||||
do ->
|
do ->
|
||||||
if proxy isnt ''
|
if proxy isnt ''
|
||||||
msg = ''
|
msg = ''
|
||||||
|
|
Loading…
Reference in New Issue