Reputation: 135
I am into a conflict. I have a schedule that generates 24 hour schedule but the thing is, on NOV 3rd at 2AM the time will change from 2AM to 1AM, means subtracting an hr. How can I handle that thing in Java. The schdule which I get from thrid party say...
The 2nd show should be 2:05 but due to time change it's 1:05. Same timing causing exception. Please help me how to handle this scenario.
Thanks
Below is the error I am getting while generating PDF schedule using XSL document in Apache FOP.
Caused by: java.lang.IndexOutOfBoundsException: Index: 450, Size: 421
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at org.apache.fop.layoutmgr.table.ColumnSetup.getXOffset(ColumnSetup.java:224)
at org.apache.fop.layoutmgr.table.TableContentLayoutManager.getXOffsetOfGridUnit(
TableContentLayoutManager.java:603) at
org.apache.fop.layoutmgr.table.TableContentLayoutManager$RowPainter.
addAreasForCell(TableContentLayoutManager.java:981)
at org.apache.fop.layoutmgr.table.TableContentLayoutManager$RowPainter.
addAreasAndFlushRow
(TableContentLayoutManager.java:943)
at org.apache.fop.layoutmgr.table.TableContentLayoutManager$RowPainter.
handleTableContentPosition(TableContentLayoutManager.java:800)
at org.apache.fop.layoutmgr.table.TableContentLayoutManager.iterateAndPaintPositions
(TableContentLayoutManager.java:754)
at org.apache.fop.layoutmgr.table.TableContentLayoutManager.addAreas
(TableContentLayoutManager.java:687)
at org.apache.fop.layoutmgr.table.TableLayoutManager.addAreas
(TableLayoutManager.java:346)
at org.apache.fop.layoutmgr.AreaAdditionUtil.addAreas(AreaAdditionUtil.java:116)
at org.apache.fop.layoutmgr.FlowLayoutManager.addAreas(FlowLayoutManager.java:297)
at org.apache.fop.layoutmgr.PageSequenceLayoutManager$PageBreaker.addAreas
(PageSequenceLayoutManager.java:356)
at org.apache.fop.layoutmgr.AbstractBreaker.addAreas(AbstractBreaker.java:507)
at org.apache.fop.layoutmgr.AbstractBreaker.addAreas(AbstractBreaker.java:370)
at org.apache.fop.layoutmgr.PageSequenceLayoutManager$PageBreaker.doPhase3
(PageSequenceLayoutManager.java:369)
at org.apache.fop.layoutmgr.AbstractBreaker.doLayout(AbstractBreaker.java:345)
at org.apache.fop.layoutmgr.AbstractBreaker.doLayout(AbstractBreaker.java:263)
Only this schedule thrown an error. So My guess in it's because of the time change. Any Idea how to accomodate/fix this.
Upvotes: 4
Views: 287
Reputation: 218808
on NOV 3rd at 2AM the time will change from 2AM to 1AM, means subtracting an hr. How can I handle that thing in Java
In some places the local time will change, in others it won't. Time itself isn't changing, just the local interpretation of that locality's representation of the "current time" (which itself remains fairly constant, or as constant as it can on this imprecisely spinning ball of rock on which we live).
The point is, you shouldn't have to subtract anything. Because nothing in the underlying data is actually changing, only a local view of that data.
How are you storing your date/time values? If you're not using UTC time for your underlying data, you should be. For the reason you're currently facing, as well as other very similar reasons which would create other very similar problems. The point is to separate the actual data being stored from any particular user's view of that data.
With underlying date/time data stored in a universal format, you can convert it on the fly when needed, usually for display purposes. (Sometimes for local calculations as well.) Libraries like Joda Time are really useful for that, and tons of time and effort have been put into understanding and solving the problem you currently face.
Upvotes: 2