Skip to content

Commit

Permalink
Updated some fuctions in time and deleted test context in logging.c.
Browse files Browse the repository at this point in the history
  • Loading branch information
ax-6 committed Aug 1, 2024
1 parent c240602 commit f515b4f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 13 deletions.
2 changes: 1 addition & 1 deletion aqvm/base/logging/logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void AqvmBaseLogging_OutputLog(const char* type, const char* code,

va_list other_info;
va_start(other_info, message);
AqvmBaseLogging_ProcessLog(time_str, type, code, message, other_info, "Test","This is a test.",NULL);
AqvmBaseLogging_ProcessLog(time_str, type, code, message, other_info, NULL);
va_end(other_info);
}

Expand Down
26 changes: 24 additions & 2 deletions aqvm/base/time/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
#include "aqvm/base/logging/logging.h"

int AqvmBaseTime_localtime(const time_t timestamp, struct tm* result) {
#ifdef __unix__
if (AqvmBaseTimeUnix_localtime(timestamp, result)) {
// TODO
return -1;
}
#elif _WIN32
if (AqvmBaseTimeWindows_localtime(timestamp, result)) {
// TODO
return -2;
}
#else
// TODO
AqvmBaseLogging_OutputLog(
"WARNING", "AqvmBaseTime_localtime_ThreadUnsafeWarning",
Expand All @@ -18,11 +29,22 @@ int AqvmBaseTime_localtime(const time_t timestamp, struct tm* result) {
return -2;
}
*result = *local_time;
#endif

return 0;
}

int AqvmBaseTime_GetCurrentTimeString(char* result) {
time_t current_time = time(NULL);
strftime(result, 28, "%Y-%m-%dT%H:%M:%S%z", localtime(&current_time));
if(result == NULL){
// TODO
return -1;
}

struct tm local_time;
if(AqvmBaseTime_localtime(time(NULL), &local_time)){
// TODO
return -2;
}
strftime(result, 28, "%Y-%m-%dT%H:%M:%S%z", &local_time);
return 0;
}
10 changes: 7 additions & 3 deletions aqvm/base/time/unix/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@

#include <time.h>

#include "aqvm/base/time/time.h"
#include "aqvm/base/logging/logging.h"
#include "aqvm/base/time/time.h"

int AqvmBaseTime_localtime(const time_t timestamp, struct tm* result) {

int AqvmBaseTimeUnix_localtime(const time_t timestamp, struct tm* result) {
if (localtime_r(result, &timestamp) != 0) {
// TODO
return -1;
}
return 0;
}
#endif
6 changes: 3 additions & 3 deletions aqvm/base/time/unix/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
// This program is licensed under the AQ License. You can find the AQ license in
// the root directory.

#ifndef AQ_AQVM_BASE_TIME_POSIX_TIME_H_
#define AQ_AQVM_BASE_TIME_POSIX_TIME_H_
#ifndef AQ_AQVM_BASE_TIME_UNIX_TIME_H_
#define AQ_AQVM_BASE_TIME_UNIX_TIME_H_

#include <time.h>

int AqvmBaseTimePosix_localtime(const time_t timestamp, struct tm* result);
int AqvmBaseTimeUnix_localtime(const time_t timestamp, struct tm* result);

#endif
#endif
9 changes: 5 additions & 4 deletions aqvm/base/time/windows/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@

#include <time.h>

#include "aqvm/base/time/time.h"
#include "aqvm/base/logging/logging.h"
#include "aqvm/base/time/time.h"

int AqvmBaseTimeWindows_localtime(const time_t timestamp, struct tm* result) {
if (localtime_s(result, &timestamp) != 0) {AqvmBaseLogging_OutputLog("AqvmBaseTimeWindows_localtime_","","",NULL);return -1;
}
return 0;
if (localtime_s(result, &timestamp) != 0) {
// TODO
return -1;
}
return 0;
}
#endif

0 comments on commit f515b4f

Please sign in to comment.