jodatime

How to use Joda DateTime date as id in Room, or how to get date in query?

泪湿孤枕 提交于 2019-12-13 03:14:41
问题 I need to write an app that uses date as id, and I must be able to update just by comparing date @Entity data class DailyCount(@PrimaryKey var date:DateTime, var summ: Double = 0.0) And here is the DAO @Query("update DailyCount set summ = :sum where date = :today") fun updateCash(today: DateTime, sum: Double) I want to make like this : @Entity data class DailyCount(@PrimaryKey var date:Date,//JodaTime containing only date var summ: Double = 0.0) Or like this: @Query("update DailyCount set

Java Mockito when-return on Object creation

◇◆丶佛笑我妖孽 提交于 2019-12-13 02:49:50
问题 I'm trying to test a class that calculates age. The method that calculates the age looks like this: public static int getAge(LocalDate birthdate) { LocalDate today = new LocalDate(); Period period = new Period(birthdate, today, PeriodType.yearMonthDay()); return period.getYears(); } Since I want the JUnit to be time-independent I want the today variable to always be January 1, 2016. To do this I tried going the Mockito.when route but am running into trouble. I first had this: public class

convert string to joda datetime gets stuck

限于喜欢 提交于 2019-12-13 02:25:44
问题 I'm trying to convert this string: 2014-01-01 00:00:00 to Joda DateTime I have tried the following: public static DateTime SimpleIso8601StringToDateTime(String date) { DateTimeFormatter df = DateTimeFormat.forPattern(CONSTS_APP_GENERAL.SIMPLE_DATE_FORMAT); return df.parseDateTime(date); } And also the following: public static DateTime SimpleIso8601StringToDateTime(String date) { DateTime dtDate = DateTime.parse(date, DateTimeFormat.forPattern(CONSTS_APP_GENERAL.SIMPLE_DATE_FORMAT)); return

Joda Period in year month day

瘦欲@ 提交于 2019-12-13 02:16:45
问题 i am using following code to get difference between 2 dates in year,month,day tenAppDTO.getTAP_PROPOSED_START_DATE()=2009-11-01 tenAppDTO.getTAP_PROPOSED_END_DATE()=2013-11-29 ReadableInstant r=new DateTime(tenAppDTO.getTAP_PROPOSED_START_DATE()); ReadableInstant r1=new DateTime(tenAppDTO.getTAP_PROPOSED_END_DATE()); Period period = new Period(r, r1); period.normalizedStandard(PeriodType.yearMonthDay()); years = period.getYears(); month=period.getMonths(); day=period.getDays(); out.println(

mongo find query on joda datetime

微笑、不失礼 提交于 2019-12-13 01:27:05
问题 i am trying to use find query in mongodb to determine the records on that specific date , the query is working fine when i pass it the normal date object and if i find according to dateCreated field, but for joda date field, i don't know how should i form a joda date right now i am using this query for normal records var from = new Date('2015-05-18T00:00:00.000Z'); var to = new Date('2016-05-19T00:00:00.000Z'); db.delivery.find( {"dateCreated" : { $gte:from,$lt:to } } ); now i also have a

Does org.joda.time.Period respect leap years?

本秂侑毒 提交于 2019-12-12 19:48:31
问题 I am doing some unit testing and have happened across this: 2015 (Not a Leap Year) LocalDate endDate = LocalDate.parse("01/03/2015", new DateTimeFormatterFactory("dd/MM/yyyy").createDateTimeFormatter()); LocalDate startDate = LocalDate.parse("25/02/2015", new DateTimeFormatterFactory("dd/MM/yyyy").createDateTimeFormatter()); org.joda.time.Period.fieldDifference(startDate, endDate).getDays(); // is -24 2016 (Leap Year) LocalDate endDate = LocalDate.parse("01/03/2016", new

How to slice a period of time into several slices in Joda Time?

牧云@^-^@ 提交于 2019-12-12 18:49:12
问题 I want to make a personal schedule manager using Java and Joda Time. The user has a certain period in a day (eg. 10am-4pm) , for each day in a month. He should be able to extract a period from his day and "add" a list of chores (ie strings) to this period. Then he will be shown the remaining portion of his day. He can extract more periods from this until he has no time periods left. He can add an extracted period back to the schedule for the day and remove all chores for that period, that is

Joda-Time 2.1 and Android - NoClassDefFoundError

ε祈祈猫儿з 提交于 2019-12-12 17:24:10
问题 Trying to use DateTime in an Android app (API 15) but get the following in logcat : E/dalvikvm(794): Unable to resolve Lorg/joda/time/base/AbstractInstant; annotation class 1383 D/AndroidRuntime(794): Shutting down VM W/dalvikvm(794): threadid=1: thread exiting with uncaught exception (group=0x409c01f8) E/AndroidRuntime(794): FATAL EXCEPTION: main E/AndroidRuntime(794): java.lang.NoClassDefFoundError: org/joda/convert/ToString E/AndroidRuntime(794): at java.lang.reflect.Method

Difference between JodaTime and Calendar for years before 1900

扶醉桌前 提交于 2019-12-12 13:31:29
问题 I'm getting different values in milliseconds for the same date in past while using JodaTime lib and java.util.Calendar. For example for the first year AD void test() { int year = 1; DateTime dt = new DateTime(year, 1,1,0,0,0,0); dt = dt.toDateTime(GregorianChronology.getInstance()); Calendar cal = Calendar.getInstance(); cal.clear(); cal.set(year, 0, 1, 0, 0, 0); DateTime endDate = new DateTime(cal.getTimeInMillis()); endDate = endDate.toDateTime(GregorianChronology.getInstance()); System.out

JodaTime-Passing a string directly to DateTime's constructor

人走茶凉 提交于 2019-12-12 13:06:09
问题 I'm on CEST timezone (+2) and I'm having some difficulties understanding how JodaTime stores DateTime. Take this code: String timeString = "2012-09-10T13:30:00+01:00"; DateTime ddateTime = new DateTime(timeString); DateTime dtLisbon = ddateTime.withZone(DateTimeZone.forID("Europe/Lisbon")); After running, the variables get the following values: timeString = '2012-09-10T13:30:00+01:00' ddateTime = '2012-09-10T14:30:00.000+02:00' dtLisbon = '2012-09-10T13:30:00.000+01:00' Why doesn't JodaTime