Skip to content

Commit

Permalink
Fixed bug causing incorrect representation of Time when DST is in eff…
Browse files Browse the repository at this point in the history
…ect.
  • Loading branch information
thallgren committed Apr 5, 2006
1 parent b15fd67 commit 25fd6df
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/C/pljava/type/Time.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @author Thomas Hallgren
*/
#include <postgres.h>
#include <utils/nabstime.h>
#include <utils/date.h>
#include <utils/datetime.h>

Expand All @@ -29,6 +30,12 @@ static TypeClass s_TimeClass;
static Type s_Timetz;
static TypeClass s_TimetzClass;

static jlong msecsAtMidnight()
{
AbsoluteTime now = GetCurrentAbsoluteTime() / 86400;
return INT64CONST(1000) * (jlong)(now * 86400);
}

static jvalue Time_coerceDatumTZ_dd(Type self, double t, bool tzAdjust)
{
jlong mSecs;
Expand All @@ -37,7 +44,7 @@ static jvalue Time_coerceDatumTZ_dd(Type self, double t, bool tzAdjust)
t += Timestamp_getCurrentTimeZone();/* Adjust from local time to UTC */
t *= 1000.0; /* Convert to millisecs */
mSecs = (jlong)floor(t);
result.l = JNI_newObject(s_Time_class, s_Time_init, mSecs);
result.l = JNI_newObject(s_Time_class, s_Time_init, mSecs + msecsAtMidnight());
return result;
}

Expand All @@ -47,7 +54,7 @@ static jvalue Time_coerceDatumTZ_id(Type self, int64 t, bool tzAdjust)
jlong mSecs = t / 1000; /* Convert to millisecs */
if(tzAdjust)
mSecs += Timestamp_getCurrentTimeZone() * 1000;/* Adjust from local time to UTC */
result.l = JNI_newObject(s_Time_class, s_Time_init, mSecs);
result.l = JNI_newObject(s_Time_class, s_Time_init, mSecs + msecsAtMidnight());
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.sql.Time;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
import java.util.logging.Logger;

Expand Down Expand Up @@ -101,7 +102,7 @@ public static void print(Date time)

public static void print(Time time)
{
DateFormat p = DateFormat.getTimeInstance(DateFormat.FULL);
DateFormat p = new SimpleDateFormat("HH:mm:ss z Z");
log("Local Time is " + p.format(time));
p.setTimeZone(TimeZone.getTimeZone("UTC"));
log("UTC Time is " + p.format(time));
Expand Down

0 comments on commit 25fd6df

Please sign in to comment.