简体   繁体   English

如何使用带有 Google 时间戳的 Xquery function fn:parse-ietf-date?

[英]How to use the Xquery function fn:parse-ietf-date with a Google timestamp?

It looks like this specific function chokes on the string which Google provides.看起来这个特定的 function 阻塞了 Google 提供的字符串。 For example:例如:

Saturday, 2 December 2017 at 15:00:32 UTC

doesn't seem to parse, at least using the basex console with this function:似乎没有解析,至少使用带有此 function 的 basex 控制台:

> 
> xquery fn:parse-ietf-date("Wed, 6 Jun 94 07:29:35 GMT") 
1994-06-06T07:29:35Z
Query executed in 0.82 ms.
> 
> xquery fn:parse-ietf-date("Sat, 2 December 2017 15:00:32 UTC") 
Stopped at ., 1/19:
[FORG0010] Invalid input ('-' expected, 'e' found): 'Sat, 2 December 2017 15:00:32 UTC'.
> xquery fn:parse-ietf-date("Sat, 2 Dec 2017 15:00:32 UTC") 
2017-12-02T15:00:32Z
Query executed in 3.45 ms.
> 
> xquery fn:parse-ietf-date("Sat, 2 Dec 2017 at 15:00:32 UTC") 
Stopped at ., 1/19:
[FORG0010] Invalid input (time expected, 'a' found): 'Sat, 2 Dec 2017 at 15:00:32 UTC'.
> 
> xquery fn:parse-ietf-date("Sat, 2 December 2017 15:00:32 UTC") 
Stopped at ., 1/19:
[FORG0010] Invalid input ('-' expected, 'e' found): 'Sat, 2 December 2017 15:00:32 UTC'.
> 

It looks like "at" causes havoc, as does a full month versus just an abbreviated month.看起来“at”会造成严重破坏,就像一个完整的月份与一个简短的月份一样。

is this function able to parse this date?这个 function 能够解析这个日期吗? If not, what alternate function might be suitable?如果没有,什么替代 function 可能合适?

Presumably Google's using a standard timestamp.大概谷歌使用标准时间戳。

(data originates from "google hangouts" exported as JSON.) (数据来自导出为 JSON 的“google hangouts”。)

When you look at the grammar of fn:parse-ietf-date() you notice not only the at but also the written out month is throwing the parser off;当您查看fn:parse-ietf-date()语法时,您会注意到不仅 at,而且写出的月份都使解析器关闭; you could fix this using fn:replace() with aa regex like that:你可以使用fn:replace()和 a 正则表达式来解决这个问题:

parse-ietf-date(
  replace('Saturday, 2 December 2017 at 15:00:32 UTC', 
        '(\w+, \d+ [A-z]\w\w)\w+ (\d{4}) at',
        '$1 $2'
  )
)

Demo 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM