Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8312779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:16:18+00:00 2026-06-08T20:16:18+00:00

Here is my code: long treatmentTimeBeginDay; if ( effectiveBegin.after(businessClosing) ) { LOGGER.debug(Compute treatment time

  • 0

Here is my code:

long treatmentTimeBeginDay;
if ( effectiveBegin.after(businessClosing) ) {
    LOGGER.debug("Compute treatment time for beginDay = 0: the effective begin {} is after business closing {}",
                            config.formatLogDate(effectiveBegin),config.formatLogDate(businessClosing));
    treatmentTimeBeginDay = 0;
} else {
    LOGGER.debug("Compute treatment time for beginDay between {} and {}",config.formatLogDate(effectiveBegin),config.formatLogDate(businessClosing));
    treatmentTimeBeginDay = businessClosing.getTime() - effectiveBegin.getTime();
}
Preconditions.checkState( treatmentTimeBeginDay >= 0 , "Internal bug! treatmentTimeBeginDay="+treatmentTimeBeginDay );

effectiveBegin and businessClosing are not null, also checked by Guava preconditions and you can see it in the logs…

It runs fine in most cases but in production we have these errors:

Caused by: java.lang.IllegalStateException: Internal bug!
treatmentTimeBeginDay=-852

I don’t give you the rest of the stack/code because it should be enough…
The exception is explicitly raised by my Guava checkState call.

I also have the log:

DEBUG [BusinessHoursUtils.java:257] llairie – Compute treatment time
for beginDay between 7/19/12 8:00 PM and 7/19/12 8:00 PM

(I can’t have log with millies for now)


What i’m trying to understand is.

If i get the log i gave you, this means that the test if ( effectiveBegin.after(businessClosing) ) is false, so effectiveBegin should be before or equals to the businessClosing.

In this case effectiveBegin timestamp should be lower than the businessClosing timestamp.

So when i do businessClosing.getTime() - effectiveBegin.getTime(); i would expect to have a positive number.

So please can someone tell me why i have -852 milliseconds in my exception message? How is this possible?


Edit: I was suspecting a tricky case where the after/before method wouldn’t work for milliseconds and it seems that’s the problem since i could reproduce it locally.

The 2 dates at runtime are:

businessClosing = {java.util.Date@503}"Thu Jul 19 20:00:00 CEST 2012"
fastTime = 1342720800000
cdate = null

effectiveBegin = {java.sql.Timestamp@498}"2012-07-19 20:00:00.999"
nanos = 999000000
fastTime = 1342720800000
cdate = {sun.util.calendar.Gregorian$Date@512}"2012-07-19T20:00:00.000+0200"

With these runtime objects, effectiveBegin.after(businessClosing) = false
If i set in DB effectiveBegin = 2012-07-19 20:00:01.000, 1 millisecond later, then the test = true

In both cases i would expect to have effectiveBegin.after(businessClosing) = true

It seems, like ametren suspected, that my dates are different.

So in the end, what’s the problem?
Aren’t we supposed to be able to compare the 2 date instance with a millisecond precision?
Even if they are subclasses of the java.util.Date?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T20:16:20+00:00Added an answer on June 8, 2026 at 8:16 pm

    The problem here is that you mix Timestamp and Date. Timestamp.after(Date) compares only the milliseconds of the Date components, which are both 1342720800000 in your example.
    However, Timestamp.getTime() does also consider the Nanoseconds (999000000ns = 999ms) that are stored within the Timestamp and will return 1342720800999. So businessClosing.getTime() - effectiveBegin.getTime() will return -999 as result.

    To solve this issue, you could modify the if-statement to if(effectiveBegin.compareTo(businessClosing) > 0) or you could convert the businessClosingDate to a Timestamp before the if-statement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Really simple question here but bugging me for long enough to ask. Code looks
My apologies for the long code sample. Here is my sample code: #include <iostream>
Hey Folks,I have pasted my code here. Dialog.inform contains a 'long' value which is
With this code vozhus very much in it for a long time tinkering that
Here is my code: long max = pcmU16.Length; long index = 0; fixed (ushort*
Here is my code: static long x = 0; void * thread_func(void *arg){ while(1){
Here my problem is: I have this code: static long CountLinesInFile(string f) { long
The script is on jsfiddle here : CODE What it does at the moment
Ok the error is showing up somewhere in this here code if($error==false) { $query
Here is code my jqgrid editing through form. $(#DataEnergy).jqGrid('navGrid', '#pagergrid', {}, //options {editdata: {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.