尝试使用“ fromdate”时出现jq“在该平台上未实现strptime / 1”

时间:2019-01-08 21:46:32

标签: json datetime jq

我在Windows 10上运行jq v1.6,

我的输入是“ 2009-12-20 08:00:00”,我想获取星期几。

我的测试过滤器是("2009-12-20 08:00:00" | sub(" "; "T") + "Z" | fromdate | gmtime) 但我得到的只是一个错误:

  

jq:错误:该平台未实现strptime / 1

尝试了很多东西,但没有任何效果。

builtins返回相关功能:

[
  "input_line_number/0",
  "input_filename/0",
  "now/0",
  "localtime/0",
  "gmtime/0",
  "mktime/0",
  "strflocaltime/1",
  "strftime/1",
  "strptime/1",
  "stderr/0",
  "debug/0",
  "modulemeta/0",
  "get_jq_origin/0",
  "get_prog_origin/0",
  "get_search_list/0",
  "halt_error/1",
  "halt/0",
  "env/0",
  "format/1",
  "error/1",
  "max/0",
  "min/0",
  "sort/0",
  "nan/0",
  "infinite/0",
  "isnormal/0",
  "isnan/0",
  "isinfinite/0",
  "type/0",
  "utf8bytelength/0",
  "length/0",
  "contains/1",
  "has/1",
  "delpaths/1",
  "getpath/1",
  "setpath/2",
  "implode/0",
  "explode/0",
  "split/1",
  "rtrimstr/1",
  "ltrimstr/1",
  "endswith/1",
  "startswith/1",
  "keys_unsorted/0",
  "keys/0",
  "tostring/0",
  "tonumber/0",
  "fromjson/0",
  "tojson/0",
  "modf/0",
  "frexp/0",
  "ldexp/2",
  "trunc/0",
  "scalbln/2",
  "round/0",
  "rint/0",
  "nexttoward/2",
  "nextafter/2",
  "nearbyint/0",
  "logb/0",
  "log1p/0",
  "lgamma/0",
  "fmod/2",
  "fmin/2",
  "fmax/2",
  "fma/3",
  "fdim/2",
  "fabs/0",
  "expm1/0",
  "erfc/0",
  "erf/0",
  "copysign/2",
  "ceil/0",
  "yn/2",
  "jn/2",
  "y1/0",
  "y0/0",
  "tgamma/0",
  "tanh/0",
  "tan/0",
  "sqrt/0",
  "sinh/0",
  "sin/0",
  "remainder/2",
  "pow/2",
  "log2/0",
  "log10/0",
  "log/0",
  "j1/0",
  "j0/0",
  "hypot/2",
  "floor/0",
  "exp2/0",
  "exp/0",
  "cosh/0",
  "cos/0",
  "cbrt/0",
  "atanh/0",
  "atan2/2",
  "atan/0",
  "asinh/0",
  "asin/0",
  "acosh/0",
  "acos/0",
  "empty/0",
  "not/0",
  "path/1",
  "range/2",
  "halt_error/0",
  "error/0",
  "map/1",
  "select/1",
  "sort_by/1",
  "group_by/1",
  "unique/0",
  "unique_by/1",
  "max_by/1",
  "min_by/1",
  "add/0",
  "del/1",
  "map_values/1",
  "recurse/1",
  "recurse/2",
  "recurse/0",
  "recurse_down/0",
  "to_entries/0",
  "from_entries/0",
  "with_entries/1",
  "reverse/0",
  "indices/1",
  "index/1",
  "rindex/1",
  "paths/0",
  "paths/1",
  "any/2",
  "any/1",
  "any/0",
  "all/2",
  "all/1",
  "all/0",
  "isfinite/0",
  "arrays/0",
  "objects/0",
  "iterables/0",
  "booleans/0",
  "numbers/0",
  "normals/0",
  "finites/0",
  "strings/0",
  "nulls/0",
  "values/0",
  "scalars/0",
  "scalars_or_empty/0",
  "leaf_paths/0",
  "join/1",
  "flatten/1",
  "flatten/0",
  "range/1",
  "fromdateiso8601/0",
  "todateiso8601/0",
  "fromdate/0",
  "todate/0",
  "match/2",
  "match/1",
  "test/2",
  "test/1",
  "capture/2",
  "capture/1",
  "scan/1",
  "splits/2",
  "splits/1",
  "split/2",
  "sub/2",
  "sub/3",
  "gsub/3",
  "gsub/2",
  "range/3",
  "while/2",
  "until/2",
  "limit/2",
  "isempty/1",
  "first/1",
  "last/1",
  "nth/2",
  "first/0",
  "last/0",
  "nth/1",
  "combinations/0",
  "combinations/1",
  "transpose/0",
  "in/1",
  "inside/1",
  "input/0",
  "repeat/1",
  "inputs/0",
  "ascii_downcase/0",
  "ascii_upcase/0",
  "truncate_stream/1",
  "fromstream/1",
  "tostream/0",
  "bsearch/1",
  "walk/1",
  "INDEX/2",
  "INDEX/1",
  "JOIN/2",
  "JOIN/3",
  "JOIN/4",
  "IN/1",
  "IN/2",
  "drem/2",
  "exp10/0",
  "gamma/0",
  "pow10/0",
  "scalb/2",
  "significand/0",
  "lgamma_r/0",
  "builtins/0"
]

1 个答案:

答案 0 :(得分:1)

以下是在Windows 10计算机上解决问题的两种替代方法:

为Windows安装Linux

然后,一旦安装了jq(例如,使用),则可以使用以下过滤器:

"2009-12-20 08:00:00"
| strptime("%Y-%m-%d %T")
| strftime("%a")

它会产生“ Sun”(这是正确的:-)

使用Zeller的一致性

# Use Zeller's Congruence to determine the day of the week, given
# year, month and day as integers in the conventional way.
# Emit 0 for Saturday, 1 for Sunday, etc.
#
def day_of_week($year; $month; $day):
  if $month == 1 or $month == 2 then
    [$month + 12, $year - 1]
  else
    [$month, $year]
  end 
  | $day + (13*(.[0] + 1)/5|floor)
    +  (.[1]%100)       + ((.[1]%100)/4|floor)
    +  (.[1]/400|floor) - 2*(.[1]/100|floor) 
  | . % 7 ;


"2009-12-20 08:00:00"
| capture("(?<Y>\\d+)-(?<m>\\d+)-(?<d>\\d+)")
| map_values(tonumber)
| day_of_week(.Y; .m; .d) 

这将产生1,表示星期日。