Comments (7)
TimestampColumnDateTimeMapper.fromNonNullValue() also is broken... see this:
// fixture
final DateTimeZone AMERICA_SAOPAULO_ZONE = DateTimeZone.forID("America/Sao_Paulo");
TimestampColumnDateTimeMapper mapper = new TimestampColumnDateTimeMapper();
mapper.setJavaZone(AMERICA_SAOPAULO_ZONE);
mapper.setDatabaseZone(AMERICA_SAOPAULO_ZONE);
Timestamp timestamp = new Timestamp(new DateTime(2013, 10, 22, 2, 0, 0, 0, AMERICA_SAOPAULO_ZONE).getMillis());
// exercise SUT
DateTime dateTime = mapper.fromNonNullValue(timestamp);
// verify
assertThat(dateTime, is(new DateTime(2013, 10, 22, 2, 0, 0, 0, AMERICA_SAOPAULO_ZONE))); // fails
from jadira.
All those tests fail! Please, see above.
import org.jadira.usertype.dateandtime.joda.columnmapper.TimestampColumnDateTimeMapper;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.junit.Before;
import org.junit.Test;
import java.sql.Timestamp;
import java.util.TimeZone;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
public class JadiraTest {
final DateTimeZone AMERICA_SAOPAULO_ZONE = DateTimeZone.forID("America/Sao_Paulo");
final DateTimeZone UTC_ZONE = DateTimeZone.UTC;
@Before
public void setup() {
// Mapper (SUT) should ignore this default time zone when .setJavaZone(..) is used!
// All tests always set a specific JavaZone
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));
}
@Test
public void toNonNullValue_UTC() throws Exception {
//
// fixture
TimestampColumnDateTimeMapper mapper = new TimestampColumnDateTimeMapper();
mapper.setJavaZone(UTC_ZONE);
mapper.setDatabaseZone(UTC_ZONE);
//
// exercise SUT
Timestamp timestamp = mapper.toNonNullValue(new DateTime(2013, 10, 22, 0, 0, 0, 0, UTC_ZONE));
//
// verify
assertThat(timestamp.getTime(), is(new DateTime(2013, 10, 22, 0, 0, 0, 0, UTC_ZONE).getMillis()));
}
@Test
public void toNonNullValue_AmericaSaoPaulo() throws Exception {
//
// fixture
TimestampColumnDateTimeMapper mapper = new TimestampColumnDateTimeMapper();
mapper.setJavaZone(AMERICA_SAOPAULO_ZONE);
mapper.setDatabaseZone(AMERICA_SAOPAULO_ZONE);
//
// exercise SUT
Timestamp timestamp = mapper.toNonNullValue(new DateTime(2013, 10, 1, 0, 0, 0, 0, AMERICA_SAOPAULO_ZONE));
//
// verify
assertThat(timestamp.getTime(), is(new DateTime(2013, 10, 1, 0, 0, 0, 0, AMERICA_SAOPAULO_ZONE).getMillis()));
}
@Test
public void toNonNullValue_AmericaSaoPaulo_DaylightSaving() throws Exception {
//
// fixture
TimestampColumnDateTimeMapper mapper = new TimestampColumnDateTimeMapper();
mapper.setJavaZone(AMERICA_SAOPAULO_ZONE);
mapper.setDatabaseZone(AMERICA_SAOPAULO_ZONE);
//
// exercise SUT
Timestamp timestamp = mapper.toNonNullValue(new DateTime(2013, 10, 22, 0, 0, 0, 0, AMERICA_SAOPAULO_ZONE));
//
// verify
assertThat(timestamp.getTime(), is(new DateTime(2013, 10, 22, 0, 0, 0, 0, AMERICA_SAOPAULO_ZONE).getMillis()));
}
@Test
public void fromNonNullValue_UTC() throws Exception {
//
// fixture
TimestampColumnDateTimeMapper mapper = new TimestampColumnDateTimeMapper();
mapper.setJavaZone(UTC_ZONE);
mapper.setDatabaseZone(UTC_ZONE);
Timestamp timestamp = new Timestamp(new DateTime(2013, 10, 22, 2, 0, 0, 0, UTC_ZONE).getMillis());
//
// exercise SUT
DateTime dateTime = mapper.fromNonNullValue(timestamp);
//
// verify
assertThat(dateTime, is(new DateTime(2013, 10, 22, 2, 0, 0, 0, UTC_ZONE)));
}
@Test
public void fromNonNullValue_AmericaSaoPaulo() throws Exception {
//
// fixture
TimestampColumnDateTimeMapper mapper = new TimestampColumnDateTimeMapper();
mapper.setJavaZone(AMERICA_SAOPAULO_ZONE);
mapper.setDatabaseZone(AMERICA_SAOPAULO_ZONE);
Timestamp timestamp = new Timestamp(new DateTime(2013, 10, 1, 2, 0, 0, 0, AMERICA_SAOPAULO_ZONE).getMillis());
//
// exercise SUT
DateTime dateTime = mapper.fromNonNullValue(timestamp);
//
// verify
assertThat(dateTime, is(new DateTime(2013, 10, 1, 2, 0, 0, 0, AMERICA_SAOPAULO_ZONE)));
}
@Test
public void fromNonNullValue_AmericaSaoPaulo_DaylightSaving() throws Exception {
//
// fixture
TimestampColumnDateTimeMapper mapper = new TimestampColumnDateTimeMapper();
mapper.setJavaZone(AMERICA_SAOPAULO_ZONE);
mapper.setDatabaseZone(AMERICA_SAOPAULO_ZONE);
Timestamp timestamp = new Timestamp(new DateTime(2013, 10, 22, 2, 0, 0, 0, AMERICA_SAOPAULO_ZONE).getMillis());
//
// exercise SUT
DateTime dateTime = mapper.fromNonNullValue(timestamp);
//
// verify
assertThat(dateTime, is(new DateTime(2013, 10, 22, 2, 0, 0, 0, AMERICA_SAOPAULO_ZONE)));
}
@Test
public void fromNonNullValue_AmericaSaoPaulo_DaylightSavingTransitionInstant() throws Exception {
//
// fixture
TimestampColumnDateTimeMapper mapper = new TimestampColumnDateTimeMapper();
mapper.setJavaZone(AMERICA_SAOPAULO_ZONE);
mapper.setDatabaseZone(AMERICA_SAOPAULO_ZONE);
long millisAtTransitionInstant = new DateTime(2013, 10, 19, 23, 59, 59, AMERICA_SAOPAULO_ZONE).getMillis() + 1000;
Timestamp timestamp = new Timestamp(millisAtTransitionInstant);
//
// exercise SUT
DateTime dateTime = mapper.fromNonNullValue(timestamp);
//
// verify
// At 'time zone offset transition' (2013-10-19 23:59:59 + 1 second), DateTime should be 2013-10-20 01:00:00.
assertThat(dateTime, is(new DateTime(2013, 10, 20, 1, 0, 0, 0, AMERICA_SAOPAULO_ZONE)));
}
}
from jadira.
If you change the database zone to UTC the tests all pass. You should only be setting the zone to something other than UTC when you are using the mapper with the JDBC driver to persist to a database with a reference time in that zone.
To verify an issue on this behaviour, we need to extend the test to perform the persistence and retrieval against a specific database product(s) running with the timezone you specified specified.
from jadira.
Which DB are you seeing an issue with?
from jadira.
All data stored in DB (SQL Server 2005) is in BRT (offset -03:00). So, I really have to set the database zone to other than UTC (I know that it's not ideal, but it can't be undone as there are a lot of data already stored there).
The Java Zone is 'America/Sao_Paulo' (offsets -03:00 and -02:00 at DST).
from jadira.
Any chance this could be fixed?
from jadira.
I am preparing 3.1.0.CR9 which changes the implementation of Database Zone. Please review and reopen the issue if it doesn't address the problem you have.
from jadira.
Related Issues (20)
- Switch to using MetadataContributor or TypeContributor for contributing types HOT 1
- DateTime Column with @Version attribute HOT 3
- Persisting FastMoney in JPA truncates amount
- Migrate from Jadira 7.0.0.CR1 to Java 17 HOT 3
- Cannot resolve method 'withZone' in 'OffsetDateTime'
- weld-core-parent dependency reference invalid xml
- TimeColumnLocalTimeMapper incorrectly uses "getNano()" HOT 1
- Jadira Usertypes with Java 10 throws java.lang.ArrayIndexOutOfBoundsException on initialisation HOT 7
- Where are lastest versions of Jadira published? HOT 2
- Update Indriya version to 1.2
- Document which version of usertypes is compatible with which version of Hibernate HOT 3
- Incompatible handling of timezones in 7.0.0.CR1 HOT 1
- Hibernate 5.3.7 compatibility HOT 2
- Joda Money 1.0 removes deprecated methods that Jadira uses
- PersistentDateTime mishandles dates that fall in DST HOT 1
- AbstractHeuristicUserType tries to instantiate deprecated TypeResolver with wrong parameters HOT 1
- StringColumnDateTimeMapper throws an Exception when Joda Datetime contains zone offset in hours, not Zone ID
- Conversion from mysql decimal column to curreny YEN fails. HOT 2
- Problem between sql Date and joda LocalDate conversion
- Status of jadira ? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jadira.