jodatime

Find if hours ranges overlap regardless of the date

大憨熊 提交于 2020-01-25 18:26:35
问题 I have a set of two hours ranges 10 PM - 02 AM 01 AM - 08 AM I want to check if any of them over lap regardless of the the date. For Example: The first range could be on 1st and 2nd of Aug while the second range could be 10th of Aug. This is what I have so far private Interval createInterval(final OpeningClosingTimesEntry entry) { LocalDateTime openingHour = LocalDateTime.fromDateFields(entry.getOpenTime()); LocalDateTime closingHour = LocalDateTime.fromDateFields(entry.getCloseTime()); if

'negative' Duration in Joda, a bug or a feature?

自作多情 提交于 2020-01-24 15:02:08
问题 When trying to compare two DateTime I wrote this code private boolean compareTime(DateTime dt1, DateTime dt2) { long d1 = (new Duration(dt1.getMillis() - dt2.getMillis())).getMillis(); long d2 = Duration.standardHours(1).getMillis(); return d1 < d2; } DateTime dt1 = new DateTime(); Thread.sleep(250); DateTime dt2 = dt1.plusHours(2); System.out.println(compareTime(dt1,dt2)); System.out.println(compareTime(dt2,dt1)); Expected this to print false false But it was true false So when I looked into

'negative' Duration in Joda, a bug or a feature?

随声附和 提交于 2020-01-24 15:02:05
问题 When trying to compare two DateTime I wrote this code private boolean compareTime(DateTime dt1, DateTime dt2) { long d1 = (new Duration(dt1.getMillis() - dt2.getMillis())).getMillis(); long d2 = Duration.standardHours(1).getMillis(); return d1 < d2; } DateTime dt1 = new DateTime(); Thread.sleep(250); DateTime dt2 = dt1.plusHours(2); System.out.println(compareTime(dt1,dt2)); System.out.println(compareTime(dt2,dt1)); Expected this to print false false But it was true false So when I looked into

Hibernate Joda DateTime Sorting

帅比萌擦擦* 提交于 2020-01-24 12:47:32
问题 I am using Joda DateTime and the UserType library for hibernate 4 I have a JPA entity with the following field @Columns(columns = { @Column(name = "lastUsedDateTimeStamp"), @Column(name = "lastUsedDateTimeStamp_TMZ") }) @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTimeAsString") private DateTime lastUsedDateTimeStamp; I am using a normal Spring Data JPA repository as follows: return repository.findAll(new PageRequest(0, 5, new Sort(Sort.Direction.DESC,

Joda Time & parsing two digit year correctly based on pivot

↘锁芯ラ 提交于 2020-01-24 05:48:04
问题 I have the following (somewhat abbreviated) code to parse String input into a Joda Time DateTime object. I need to properly handle multiple formats, including four & two digit years. setupValidDateFormats(); DateTime date = convertToDateTime(thisField.getText()); if (date != null) { thisField.setText(date.toString("MM/dd/yyyy")); } else { System.out.println("Invalid date"); } private void setupValidDateFormats() { DateTimeParser[] formats = { DateTimeFormat.forPattern("MM/dd/yyyy").getParser(

Get the week start and end date given a current date and week start

半腔热情 提交于 2020-01-18 05:47:31
问题 If possible I would prefer a joda or non-joda solution for the scenario below Lets say if my week starts on 02/05/2012 and the given current date is 02/22/2011. I need to calculate the week start and end date for the given current date. So my solution should have the week start as 02/19 and week ends at 02/25. For simplicity, I have set my week start here as 02/05/2011 but it could be any day potentially and my week always has 7 days. My existing code is below but doesnt seem to work as

Get the week start and end date given a current date and week start

做~自己de王妃 提交于 2020-01-18 05:47:06
问题 If possible I would prefer a joda or non-joda solution for the scenario below Lets say if my week starts on 02/05/2012 and the given current date is 02/22/2011. I need to calculate the week start and end date for the given current date. So my solution should have the week start as 02/19 and week ends at 02/25. For simplicity, I have set my week start here as 02/05/2011 but it could be any day potentially and my week always has 7 days. My existing code is below but doesnt seem to work as

Dataframe- minus minutes from timestamp column

Deadly 提交于 2020-01-17 05:50:07
问题 Environment: Spark 1.6 ; Scala Simple question, but I did not get accurate answer. I have a dataframe DF id | cr_date ----------------------- 1| 2017-03-17 11:12:00 ---------------------- 2|2017-03-17 15:10:00 I need to minus 5 minutes from cr_date. I tried val DF2= DF.select ($"cr_Date".cast("timestamp").minusMinutes(5)) // Did not work Any suggestion? Thanks 回答1: df.select(from_unixtime(unix_timestamp(col("cr_dt")).minus(5 * 60), "YYYY-MM-dd HH:mm:ss")) There is no such minusMinutes method

Displaying “negative” time periods with Joda-Time PeriodFormatter

对着背影说爱祢 提交于 2020-01-14 17:16:51
问题 I'm using joda-time (1.6.2) on a project and one of the things I'm doing is getting the difference between a predicted time and an actual time. Sometimes this difference is positive, sometimes negative. While the appropriate approach may be to use a Duration rather than a Period , using a PeriodFormatter to display the result led me a question about the PeriodFormatterBuilder class. As an example: DateTime d1 = new DateTime(2011, 6, 17, 13, 13, 5, 0) ; DateTime d2 = new DateTime(2011, 6, 17,

how to convert from ZonedDateTime to Joda DateTime

℡╲_俬逩灬. 提交于 2020-01-14 07:33:22
问题 I've switched to threeten for date times but I've still got a 3rd party tool that uses joda to write timestamp with timezone to the database and I need to convert from one to the other. What's the best way? As a workaround I tried DateTime.parse(zdt.toString) but it falls over because joda doesn't like the zone format Invalid format: "2015-01-25T23:35:07.684Z[Europe/London]" is malformed at "[Europe/London]" 回答1: ZonedDateTime zdt = ZonedDateTime.of( 2015, 1, 25, 23, 35, 7, 684000000, ZoneId