File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GregorianCalendar with negative time

 
Steve Jiang
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found an issue in code that GregorianCalendar with negative time and ERA as BC as below.
java.util.GregorianCalendar[time=-125520479618000,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="GMT",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=0,YEAR=2009,MONTH=5,WEEK_OF_YEAR=25,WEEK_OF_MONTH=4,DAY_OF_MONTH=17,DAY_OF_YEAR=169,DAY_OF_WEEK=1,DAY_OF_WEEK_IN_MONTH=3,AM_PM=1,HOUR=4,HOUR_OF_DAY=16,MINUTE=6,SECOND=22,MILLISECOND=0,ZONE_OFFSET=0,DST_OFFSET=0]

notice
time=-125520479618000,
ERA=0

It is only happened for the certain date, most other time and calendar are correct.


Good calenda

java.util.GregorianCalendar[time=1186393080000,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="GMT",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2007,MONTH=7,WEEK_OF_YEAR=32,WEEK_OF_MONTH=2,DAY_OF_MONTH=6,DAY_OF_YEAR=218,DAY_OF_WEEK=2,DAY_OF_WEEK_IN_MONTH=1,AM_PM=0,HOUR=9,HOUR_OF_DAY=9,MINUTE=38,SECOND=0,MILLISECOND=0,ZONE_OFFSET=0,DST_OFFSET=0]


here
time=118639308000
ERA=1


Is there any case the GregorianCalendar could get the negative time ? Any suggestions are appreciated!
 
Darryl Burke
Bartender
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Jiang wrote:Is there any case the GregorianCalendar could get the negative time ? Any suggestions are appreciated!


The long value representing the time will be negative for any date/time before the epoch.
 
Steve Jiang
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The date based on calendar is about 2009/05/17, obviously after epoch, how come to negative time?
 
Steve Jiang
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the negative time is caused by ERA setting as 0 (BC) , I am wondering what reason could cause this issue? Thanks
 
Darryl Burke
Bartender
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
2009 BC is obviously before the epoch.
 
Steve Jiang
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have some sample code as below,



and I get the result

JDBC Connect Example.
2009-06-17 16:06:22.893
new time in Millis from time is -125520450817107
Connected to the database
Disconnected from database


Looks like the DB result is OK like 2009-06-17 16:06:22.893, but the time is negative as -125520450817107.

How can we identify the DB data when it has negative time value?



 
Steve Jiang
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I mean , for the data get from SQL, how could we know if the data is set as BC (or how to detect the wrong data with BC date) without converting it to Mill Seconds.

Thanks
 
Radhakrishna Sharma Gorenta
Ranch Hand
Posts: 63
Google App Engine Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please explain some what briefly? what actually you want to know??
 
Steve Jiang
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the data in DB looks correct when retrieving with SQL as 2009/06/07, but it shows as negative time after convert as mill seconds. what is caused the issue, and how can we detect the bad data with SQL?

 
Paul Clapham
Sheriff
Pie
Posts: 20196
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Jiang wrote:If the negative time is caused by ERA setting as 0 (BC) , I am wondering what reason could cause this issue? Thanks


The obvious reason would be that it's that way in the database.

How can we identify the DB data when it has negative time value?


That's a question about some unknown database, isn't it? Probably you know what the database is, but we don't. But just using basic SQL,
if you display a query which is sorted on the column containing that date, then the row containing that date should come at or near the
beginning.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic