解析Joda-Time Partials [英] Parsing Joda-Time Partials

查看:104
本文介绍了解析Joda-Time Partials的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Strings中生成Partials,但在支持它的API中找不到任何内容。显然,我可以在Joda-Time框架之外编写自己的解析器并创建Partials,但我无法想象API还没有能力做到这一点。

I'd like to produce Partials from Strings, but can't find anything in the API that supports that. Obviously, I can write my own parser outside of the Joda-Time framework and create the Partials, but I can't imagine that the API doesn't already have the ability to do this.

使用threeten(JSR-310)将是一个可接受的解决方案,但它似乎不支持Partials。我不知道这是否是由于它的alpha状态,或者Partial概念是否以不同的方式处理,我还没有发现。

Use of threeten (JSR-310) would be an acceptable solution, but it doesn't seem to support Partials. I don't know whether that is due to its alpha status, or whether the Partial concept is handled in a different manner, which I haven't discovered.

什么是将字符串(2011年,02/11等)转换为部分字符串的最佳方法?

What is the best way to convert a String (2011, 02/11, etc) into a Partial?

推荐答案

我已经扩展了DateTimeParserBucket 。我的扩展类拦截对saveField()方法的调用,并在委托给super之前存储字段类型和值。我还实现了一个使用这些存储的字段值来创建Partial的方法。

I've extended DateTimeParserBucket. My extended class intercepts calls to the saveField() methods, and stores the field type and value before delegating to super. I've also implemented a method that uses those stored field values to create a Partial.

我能够将我的存储桶实例传递给DateTimeParser.parseInto(),并且然后要求它创建Partial。

I'm able to pass my bucket instance to DateTimeParser.parseInto(), and then ask it to create the Partial.

它有效,但我不能说我对Joda-Time印象深刻 - 因为它不支持解析Partials盒子外面。缺少DateTimeFormatter.parsePartial(String)是一个明显的遗漏。

It works, but I can't say I'm impressed with Joda-Time - given that it doesn't support parsing Partials out of the box. The lack of DateTimeFormatter.parsePartial(String) is a glaring omission.

这篇关于解析Joda-Time Partials的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆