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 8630789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:07:29+00:00 2026-06-12T09:07:29+00:00

I have a test: @Test public void testJodaStartDate2a() { DateTime dateTime = new DateTime(2010,10,10,4,0,

  • 0

I have a test:

@Test
public void testJodaStartDate2a() {

    DateTime dateTime = new DateTime(2010,10,10,4,0, DateTimeZone.forID("America/Caracas"));

    MutableDateTime mutableDateTime = dateTime.toMutableDateTime();
    mutableDateTime.setDate(dateTime);
    assertEquals(dateTime, mutableDateTime.toDateTime());
}

It’s straightforward, and in it I want to set the date part of dateTime value to the date part of dateTime value, which should be valid, and the assertion should succeed. However it fails.

As I can’t debug the methods of Joda, I created another test, which emulates what setDate() must do:

@Test
public void testJodaStartDate() {

    DateTime dateTime = new DateTime(2010,10,10,4,0, DateTimeZone.forID("America/Caracas"));

    long instantMillis = DateTimeUtils.getInstantMillis(dateTime);
    Chronology instantChrono = DateTimeUtils.getInstantChronology(dateTime);
    DateTimeZone zone1 = instantChrono.getZone();
    if (zone1 != null) {
        instantMillis = zone1.getMillisKeepLocal(DateTimeZone.UTC, instantMillis);
    }

    MutableDateTime mutableDateTime = dateTime.toMutableDateTime();
    mutableDateTime.setMillis(mutableDateTime.getChronology().millisOfDay().set(instantMillis,
                                                                                mutableDateTime.getMillisOfDay()));
    assertEquals(dateTime, mutableDateTime);
}

This test is a copy of setDate()’s contents. As I have seen during debugging, at first, after

long instantMillis = DateTimeUtils.getInstantMillis(dateTime);

the instantMillis variables is assigned a value of 1286699400000 which is 2010-10-10 04:00 (VET) and 2010-10-10 08:30 (UTC).

After

instantMillis = zone1.getMillisKeepLocal(DateTimeZone.UTC, instantMillis);

the instantMillis is 1286683200000, which is 2010-10-10 00:00 (VET) and 2010-10-10 04:00 (UTC).

At assertion, the milliseconds value of mutableDateTime is 1286613000000 which is 2010-10-09 04:00 (VET) and 2010-10-09 08:30 (UTC)..

Isn’t this function just supposed to recalculate the date part of mutableDateTime to the date part of parameter value? What am I missing in the tests? I am very much appreciated.

  • 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-12T09:07:29+00:00Added an answer on June 12, 2026 at 9:07 am

    You appear to have discovered a bug.

    The following line is wrong — it should use the time zone that this is using.

    instantMillis = zone1.getMillisKeepLocal(DateTimeZone.UTC, instantMillis);
    

    A quick search hasn’t found a current bug. I’ve filed one now (here).

    Some tests I ran to check which time zones were problematic for this time. Basically it seems that the problem occurs when the date at given time zone is different to the date at UTC (at the same instant).

    @Test
    public void minus0401() {
        DateTime dateTime = new DateTime("2010-10-10T04:00:00",
                DateTimeZone.forOffsetHoursMinutes(-4, 1));
        testDate(dateTime);
    }
    
    @Test
    public void testIds() {
        List<String> failedIds = new ArrayList<>();
        for (String id : DateTimeZone.getAvailableIDs()) {
            DateTime dateTime = new DateTime("2010-10-10T04:00:00",
                    DateTimeZone.forID(id));
            try {
                testDate(dateTime);
            } catch (AssertionError e) {
                failedIds.add(id);
            }
        }
        assertEquals(failedIds.toString(), 0, failedIds.size());
    }
    
    @Test
    public void testHours() {
        List<Integer> failedHours = new ArrayList<>();
        for (int i = -12; i < 12; i++) {
            DateTime dateTime = new DateTime("2010-10-10T04:00:00",
                    DateTimeZone.forOffsetHours(i));
            try {
                testDate(dateTime);
            } catch (AssertionError e) {
                failedHours.add(i);
            }
        }
        assertEquals(failedHours.toString(), 0, failedHours.size());
    }
    
    private void testDate(DateTime dateTime) {
        MutableDateTime mutableDateTime = dateTime.toMutableDateTime();
        mutableDateTime.setDate(dateTime);
        assertEquals(dateTime, mutableDateTime.toDateTime());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this test [Test] public void SaveInventoryItemLoad_Will_Call_WCF_Service_SaveInventoryItemLoad() { adapter.SaveInventoryItemLoad(new List<InventoryItemLoadProxy>()); itemMasterBusinessClientMock.Verify(x => x.SaveInventoryItemLoad(It.IsAny<List<InventoryItemLoadProxy>>()),
Say I have this test: [Test] public void SomeTest() { var message = new
I have this test [Fact] public void Get_if_item_is_not_in_cache_return_null_returns_true() { var repo = new Repository<IProduct>(
I have this unit test: public void testDeEscapeResponse() { final String[] inputs = new
I have this test in my test base: public void WorksWithAreaUsers() { using (new
I Have the following test: [Test] public void Add_New_Group_Should_Return_StatusCode_Created_And_A_Header_Location_To_The_New_Group() { var newGroup = new
I have the following test: [Test] public void VerifyThat_WhenInitializingTheLoggingInterceptionFacility_TheLoggingInterceptorIsAdded() { var kernel = new
I have the following test - public void testStore() throws ItemNotStoredException { Boolean result
I have a following test @Test public void testPutDocuments() throws Exception { final DBObject
I have a unit test like so: [Test] public void DataIn_NoOfRowsReached_CreatesSequentialData() { //Assert MyLogic

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.