alblue / com.packtpub.e4

Code samples for the "Eclipse Plugin Development by Example: Beginners Guide" book 978-1782160328
Eclipse Public License 1.0
55 stars 37 forks source link

Different Timezone calculations in ViewerComparator and LabelProvider #5

Open etiennestuder opened 10 years ago

etiennestuder commented 10 years ago

In TimeZoneLabelProvider#getStyledText, the offset calculation should be like this: int offset = ((TimeZone) element).getOffset(System.currentTimeMillis());

rather than: int offset = -((TimeZone) element).getOffset(0);

since this is also how the offset is calculated in TimeZoneViewerComparator.

Without this fix, the offsets displayed in the UI are not sorted and the minus/plus prefix is reverse.

Great book, btw! :-)

tony-- commented 7 years ago

Thanks for the fix @etiennestuder - but it took me a couple minutes to work out WHY it fixes the issue.

The labels are not actually used for sorting - that's the point. Because they are not used for sorting the mismatched values makes the sorted zones appear to be unsorted. Just to be clear, the zones are sorted correctly, but the offsets displayed in the labels do not match the ones used for sorting. The effect is that the zones appear to not be sorted.