jodatime

How to compare two Joda time Periods

好久不见. 提交于 2019-12-08 15:47:14
问题 It does not seem straighforward. I am trying this: @Override public int compare(Period o1, Period o2) { return o1.toStandardDays().getDays() > o2.toStandardDays().getDays() ? -1 : (o1.toStandardDays().getDays() == o2.toStandardDays().getDays() ? 0 : 1); } But I get this exception: java.lang.UnsupportedOperationException: Cannot convert to Days as this period contains months and months vary in length at org.joda.time.Period.checkYearsAndMonths(Period.java:1455) at org.joda.time.Period

Get Military Time Zone Abbreviation

旧巷老猫 提交于 2019-12-08 14:39:57
问题 I have a org.joda.time.DateTime object and I need to retrieve the military time zone abbreviation (e.g. T for UTC-07:00, U for UTC-08:00, Z for UTC±00:00). See http://en.wikipedia.org/wiki/List_of_military_time_zones Here's how I'm currently doing it: int offset = dt.getZone().toTimeZone().getRawOffset() / (60 * 60 * 1000); String timeZoneCode = timeZoneCodeMap.get(offset); where timeZoneCodeMap is a HashMap<Integer, String> that is initialized with entries like the following timeZoneCodeMap

JPA Saving wrong date in MySQL database

雨燕双飞 提交于 2019-12-08 10:38:26
问题 I have a table in my MySQL database that has a date column: +-------------------+---------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------------+---------------+------+-----+---------+----------------+ | id | bigint(20) | NO | PRI | NULL | auto_increment | | type | varchar(50) | NO | | NULL | | | expiration | date | NO | | NULL | | I'm using MySQL with JPA to save dates. I have a feature that the user can select a final date range

anorm joda-time - localdatetime support

本秂侑毒 提交于 2019-12-08 07:00:45
问题 With Anorm 2.5.2 SQL(s"insert into user (name, registered_date) values ({name},{registered_date})").on( 'name -> user.name, 'registered_date -> user.registeredDate ).executeInsert() Compilation error: Error:(72, 24) type mismatch; found : (Symbol, org.joda.time.LocalDateTime) required: anorm.NamedParameter 'registered_date -> user.registeredDate Should I include some implicit Time->Row transformation or it should come out of the box with anorm? where user: case class User(id: Option[Long] =

Deserialising string to map with multiple types using jackson

て烟熏妆下的殇ゞ 提交于 2019-12-08 05:27:03
问题 I have seen answers like this one that show the use of TypeFactory.constructMapType(...) to de-serialise a JSON string to a map where the key/value combinations are other than String . I have a situation where I have strings that should de-serialise to multiple different types, not just one. I realise that one solution would be define my own class and not use Map , but I am wondering if I can use pure configuration instead? Here is my test code. import java.util.HashMap; import java.util.Map;

Joda-Time DateTime.toDate() reverts back timezone

随声附和 提交于 2019-12-08 04:13:23
问题 I am trying to convert from one timezone to another using Joda-Time. final DateTimeZone fromTimeZone = DateTimeZone.forID("America/Los_Angeles"); final DateTimeZone toTimeZone = DateTimeZone.forID(toTimeZoneString); DateTime convertedStart = new DateTime(start, fromTimeZone).withZone(toTimeZone); Date finalS = convertedStart.toDate(); I see that finalS loses the timezone and is reverted back to the original timezone when I do .toDate() . convertedStart is correctly converted. start is in

NPE in spark with Joda DateTime

余生颓废 提交于 2019-12-08 03:07:59
问题 When executing simple mapping in spark on joda DateTime field I am receving NullPointerException. Code snippet: val me1 = (accountId, DateTime.now()) val me2 = (accountId, DateTime.now()) val me3 = (accountId, DateTime.now()) val rdd = spark.parallelize(List(me1, me2, me3)) val result = rdd.map{case (a,d) => (a,d.dayOfMonth().roundFloorCopy())}.collect.toList Stacktrace: java.lang.NullPointerException at org.joda.time.DateTime$Property.roundFloorCopy(DateTime.java:2280) at x.y.z.jobs.info

Convert Joda-Time `DateTime` with timezone to DateTime without timezone?

元气小坏坏 提交于 2019-12-08 02:15:42
问题 Given a DateTime for example 2015-07-09T05:10:00+02:00 using Joda-Time? How can I convert it to local time, meaning adding the timezone to the time itself. Desired output: 2015-07-09T07:10:00 I tried dateTime.toDateTime(DateTimeZone.UTC) but that did not give the desired result. 回答1: What @Nazgul said is right, but in case all you want to achieve is a "wall-time" in UTC zone you can do something like that: DateTime dateTimePlus2 = DateTime.parse("2015-07-09T05:10:00+02:00"); System.out

Grails controller unit tests with Joda Time

别来无恙 提交于 2019-12-08 01:59:29
问题 Some of the controller tests that generate-all creates are failing when I have a domain object with a Joda LocalDateTime field. $ grails create-app bugdemo $ cd bugdemo $ grails create-domain-class Item Edit grails-app/domain/bugdemo/Item.groovy package bugdemo import org.joda.time.LocalDateTime class Item { String name // LocalDateTime opening static constraints = { name blank:false } } Add the following line to BuildConfig.groovy compile ":joda-time:1.4" Continue at the command line $

Play Framework 2.1 Remove a core dependency

谁都会走 提交于 2019-12-08 01:57:06
问题 since a few day now i'm trying to use Joda-time 1.6.2 on a play project. I know the play framework already come with the Joda-time 2.1 and it should be compatible with 1.6.2 according to joda-time site. I'm trying to write an application that ask the user for a LocalDateTime and save the class with the attributes on a MongoDB using morphia. I'm facing a problem, i have to use a class that are currently using joda-time 1.6.2 and i cannot change it dependency neither update it to 2.1. Since i