2015-03-13 18:52:59 +00:00
|
|
|
/* Copyright (c) 2008-2015, Avian Contributors
|
2008-06-16 16:08:51 +00:00
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software
|
|
|
|
for any purpose with or without fee is hereby granted, provided
|
|
|
|
that the above copyright notice and this permission notice appear
|
|
|
|
in all copies.
|
|
|
|
|
|
|
|
There is NO WARRANTY for this software. See license.txt for
|
|
|
|
details. */
|
|
|
|
|
|
|
|
#include "time.h"
|
2011-06-01 19:56:03 +00:00
|
|
|
#include "jni.h"
|
2008-06-16 16:08:51 +00:00
|
|
|
#include "jni-util.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2014-06-30 15:53:09 +00:00
|
|
|
#if (!defined PLATFORM_WINDOWS) || (defined _MSC_VER)
|
|
|
|
|
2014-07-11 15:50:18 +00:00
|
|
|
void removeNewline(char* s)
|
2008-06-16 16:08:51 +00:00
|
|
|
{
|
|
|
|
for (; s; ++s) {
|
|
|
|
if (*s == '\n') {
|
|
|
|
*s = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-30 15:53:09 +00:00
|
|
|
#endif
|
|
|
|
|
2014-07-11 15:50:18 +00:00
|
|
|
} // namespace
|
2008-06-16 16:08:51 +00:00
|
|
|
|
|
|
|
extern "C" JNIEXPORT jstring JNICALL
|
2014-07-11 15:50:18 +00:00
|
|
|
Java_java_util_Date_toString(JNIEnv* e, jclass c UNUSED, jlong when)
|
2008-06-16 16:08:51 +00:00
|
|
|
{
|
2009-08-27 00:26:44 +00:00
|
|
|
const unsigned BufferSize UNUSED = 27;
|
|
|
|
|
2008-06-16 16:08:51 +00:00
|
|
|
time_t time = when / 1000;
|
|
|
|
|
2009-08-27 00:26:44 +00:00
|
|
|
#ifdef PLATFORM_WINDOWS
|
2008-06-16 16:08:51 +00:00
|
|
|
e->MonitorEnter(c);
|
2014-07-11 15:50:18 +00:00
|
|
|
#ifdef _MSC_VER
|
2009-08-27 00:26:44 +00:00
|
|
|
char buffer[BufferSize];
|
|
|
|
ctime_s(buffer, BufferSize, &time);
|
|
|
|
removeNewline(buffer);
|
2014-07-11 15:50:18 +00:00
|
|
|
#else
|
2009-08-27 00:26:44 +00:00
|
|
|
char* buffer = ctime(&time);
|
2014-07-11 15:50:18 +00:00
|
|
|
#endif
|
2009-08-27 00:26:44 +00:00
|
|
|
jstring r = e->NewStringUTF(buffer);
|
2008-06-16 16:08:51 +00:00
|
|
|
e->MonitorExit(c);
|
|
|
|
return r;
|
|
|
|
#else
|
2009-08-27 00:26:44 +00:00
|
|
|
char buffer[BufferSize];
|
2008-06-16 16:08:51 +00:00
|
|
|
ctime_r(&time, buffer);
|
|
|
|
removeNewline(buffer);
|
|
|
|
return e->NewStringUTF(buffer);
|
|
|
|
#endif
|
|
|
|
}
|