Perl的Mojo::XMLRPC和操作Mojo::Date格式。

huangapple go评论59阅读模式
英文:

Perl's Mojo::XMLRPC and manipulating Mojo::Date format

问题

我受到启发使用 Mojo::XMLRPC 后阅读了 The Mojolicious Blog - Day 11。我在 Mojo::Date 格式方面遇到了问题。

  1. encode_xmlrpc 期间,<dateTime.iso8601>2023-06-14T19:45:48Z。我需要它为:20230614T22:45:48+0300

  2. decode_xmlrpc 期间,当 <dateTime.iso8601>20230608T12:00:00+0000 时,我遇到错误:

在 strptime 中字符串末尾有垃圾: +0000位于 /usr/local/opt/perl/lib/perl5/5.36/darwin-thread-multi-2level/Time/Piece.pm 的第 598
也许一个格式标志没有匹配实际输入位于 /usr/local/opt/perl/lib/perl5/5.36/darwin-thread-multi-2level/Time/Piece.pm 的第 598

编辑:我认为在 XMLRPC.pm$time_format 数组前面缺少 '%H:%M:%S%z' 是我的问题(?)。

我如何指示 Mojo::XMLRPC (或 Mojo::Date?)使用所需的 DateTime 格式?

以下是示例代码:

#!/usr/bin/env perl
使用 Mojo::XMLRPC qw[encode_xmlrpc decode_xmlrpc];
使用 Data::Dumper;

我的 $e = encode_xmlrpc(call => TaregtMethod => {originTimeStamp=>Mojo::Date->new(time)});
say STDERR Dumper($e);

我的 $xml = <<'XML';
<?xml version="1.0" encoding="utf-8"?>
<methodResponse>
  <params>
    <param>
      <value>
        <struct>
          <member>
            <name>activationDate</name>
            <value>
              <dateTime.iso8601>20230608T12:00:00+0000</dateTime.iso8601>
            </value>
          </member>
        </struct>
      </value>
    </param>
  </params>
</methodResponse>
XML

我的 $d = decode_xmlrpc($xml);
say STDERR Dumper($d);
英文:

I was inspired to use Mojo::XMLRPC after reading The Mojolicious Blog - Day 11. I'm having problems with Mojo::Date format.

  1. During encode_xmlrpc, <dateTime.iso8601> is 2023-06-14T19:45:48Z. Instead, I need it as: 20230614T22:45:48+0300

  2. During decode_xmlrpc, I get an error when <dateTime.iso8601> is 20230608T12:00:00+0000:

Garbage at end of string in strptime: +0000 at /usr/local/opt/perl/lib/perl5/5.36/darwin-thread-multi-2level/Time/Piece.pm line 598.
Perhaps a format flag did not match the actual input? at /usr/local/opt/perl/lib/perl5/5.36/darwin-thread-multi-2level/Time/Piece.pm line 598.

EDIT: I believe a missing '%H:%M:%S%z' at the front of $time_format array in XMLRPC.pm is my issue (?)

How can I instruct Mojo::XMLRPC (or Mojo::Date?) to use the desired DateTime format?

Sample code below:

#!/usr/bin/env perl
use Mojo::XMLRPC qw[encode_xmlrpc decode_xmlrpc];
use Data::Dumper;

my $e = encode_xmlrpc(call => TaregtMethod => {originTimeStamp=>Mojo::Date->new(time)});
say STDERR Dumper($e);

my $xml = <<'XML';
<?xml version="1.0" encoding="utf-8"?>
<methodResponse>
  <params>
    <param>
      <value>
        <struct>
          <member>
            <name>activationDate</name>
            <value>
              <dateTime.iso8601>20230608T12:00:00+0000</dateTime.iso8601>
            </value>
          </member>
        </struct>
      </value>
    </param>
  </params>
</methodResponse>
XML

my $d = decode_xmlrpc($xml);
say STDERR Dumper($d);

答案1

得分: 2

问题出在另一端。

encode_xmlrpc 过程中,<dateTime.iso8601>2023-06-14T19:45:48Z。相反,我需要它为:20230614T22:45:48+0300

这是不可配置的,并且这不是有效的 iso8601 序列化。

decode_xmlrpc 过程中,当 <dateTime.iso8601>20230608T12:00:00+0000 时,我会收到一个错误:

这是可以预期的,因为该字符串不是有效的 iso8601 序列化。


可在 DateTime::Format::ISO8601 文档中找到有效的 iso8601 格式。

Mojo::XMLRPC 并不接受所有这些格式,它接受许多其他不属于 iso8601 的格式。

英文:

The problem is at the other end.

> During encode_xmlrpc, <dateTime.iso8601> is 2023-06-14T19:45:48Z. Instead, I need it as: 20230614T22:45:48+0300

It's not configurable, and that's not a valid iso8601 serialization.

> During decode_xmlrpc, I get an error when <dateTime.iso8601> is 20230608T12:00:00+0000:

That's to be expected since the string isn't a valid iso8601 serialization.


Valid iso8601 formats can be found in the documentation for DateTime::Format::ISO8601.

Mojo::XMLRPC doesn't accept all of them, and it accepts many other formats that aren't part of iso8601.

huangapple
  • 本文由 发表于 2023年6月15日 04:20:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76477254.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定