Fix histogram current event and time stamp format parsing

The parsing of date format is updated to use the time stamp format's
time zone.

DAY_OF_YEAR field is not copied from the reference time as setting it
also updates the MONTH and DATE, causing premature break out of the
field-copying loop.

HOUR_OF_DAY field is used to copy from the reference time instead of
the HOUR field, as the latter only uses a 12-hour clock.

The current event text control now uses the current event time value as
a reference time for parsing, instead of the trace start time. This
allows a time stamp format preference, which contains insufficient date
and time fields to fully represent the whole trace range, to be usable
in the text control. The non-visible date and time fields are assumed to
be set equal to those of the current event.

Change-Id: I25c67787c20aa26a0f267f8d460b441b74185122
Reviewed-on: https://git.eclipse.org/r/9051
Tested-by: Hudson CI
Reviewed-by: Bernd Hufmann <bhufmann@gmail.com>
IP-Clean: Bernd Hufmann <bhufmann@gmail.com>
Tested-by: Bernd Hufmann <bhufmann@gmail.com>
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimestampFormat.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimestampFormat.java
index a8bf8a8..d262370 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimestampFormat.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfTimestampFormat.java
@@ -500,25 +500,23 @@
         if (seconds == -1) {
             Date baseDate = super.parse(sb.toString());
 
-            Calendar refTime = Calendar.getInstance(TimeZone.getTimeZone("UTC")); //$NON-NLS-1$
+            Calendar refTime = Calendar.getInstance(getTimeZone());
             refTime.setTimeInMillis(ref / 1000000);
-            Calendar newTime = Calendar.getInstance(TimeZone.getTimeZone("UTC")); //$NON-NLS-1$
+            Calendar newTime = Calendar.getInstance(getTimeZone());
             newTime.setTimeInMillis(baseDate.getTime());
 
-            int[] fields = new int[] { Calendar.YEAR, Calendar.DAY_OF_YEAR, Calendar.MONTH, Calendar.DATE, Calendar.HOUR, Calendar.MINUTE, Calendar.SECOND };
+            int[] fields = new int[] { Calendar.YEAR, Calendar.MONTH, Calendar.DATE, Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND };
             for (int field : fields) {
                 int value = newTime.get(field);
                 // Do some adjustments...
                 if (field == Calendar.YEAR) {
                     value -= 1970;
-                } else if (field == Calendar.DATE || field == Calendar.DAY_OF_YEAR) {
+                } else if (field == Calendar.DATE) {
                     value -= 1;
                 }
                 // ... and fill-in the empty fields
                 if (value == 0) {
                     newTime.set(field, refTime.get(field));
-                } else if (field == Calendar.DAY_OF_YEAR) {
-                    newTime.set(field, value);
                 } else {
                     break; // Get out as soon as we have a significant value
                 }
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramCurrentTimeControl.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramCurrentTimeControl.java
index 678110e..91b7d35 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramCurrentTimeControl.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramCurrentTimeControl.java
@@ -78,7 +78,7 @@
         String string = fTextValue.getText();
         long value = 0;
         try {
-            value = TmfTimestampFormat.getDefaulTimeFormat().parseValue(string, fTraceStartTime);
+            value = TmfTimestampFormat.getDefaulTimeFormat().parseValue(string, getValue());
         } catch (ParseException e) {
         }
         if (getValue() != value) {