Skip to content

Commit

Permalink
change time format
Browse files Browse the repository at this point in the history
  • Loading branch information
hishizuka committed Oct 20, 2023
1 parent 20c3644 commit 6ace838
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
6 changes: 4 additions & 2 deletions logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def flush(self):


class CustomRotatingFileHandler(RotatingFileHandler):

def doRollover(self):
format = "%Y-%m-%d_%H-%M-%S"
if self.stream:
self.stream.close()
self.stream = None
Expand All @@ -38,7 +40,7 @@ def doRollover(self):
match = re.match(regex, f)
if match:
try:
date = datetime.fromisoformat(match.group(1))
date = datetime.strptime(match.group(1), format)
if date < cut_out_date:
os.remove(f)
except Exception:
Expand All @@ -51,7 +53,7 @@ def doRollover(self):

self.rotate(
self.baseFilename,
f"{base_filename_no_ext}-{last_date.isoformat()}{ext}",
f"{base_filename_no_ext}-{last_date.strftime(format)}{ext}",
)
if not self.delay:
self.stream = self._open()
Expand Down
8 changes: 4 additions & 4 deletions modules/logger/cython/logger_fit_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,9 @@ bool write_log_c(const char* db_file) {

//write fit file
time_t startdate_local_epoch = start_date_epoch+epoch_datetime_sec;
char startdate_local[15], filename[100], startdate_str[20];
strftime(startdate_local, sizeof(startdate_local), "%Y%m%d%H%M%S", localtime(&startdate_local_epoch));
strftime(startdate_str, sizeof(startdate_str), "%Y%m%d%H%M%S.fit", localtime(&startdate_local_epoch));
char startdate_local[20], filename[100], startdate_str[25];
strftime(startdate_local, sizeof(startdate_local), "%Y-%m-%d_%H-%M-%S", localtime(&startdate_local_epoch));
strftime(startdate_str, sizeof(startdate_str), "%Y-%m-%d_%H-%M-%S.fit", localtime(&startdate_local_epoch));
sprintf(filename, "%s/%s", cfg.G_LOG_DIR, startdate_str);

//make file header
Expand Down Expand Up @@ -652,7 +652,7 @@ bool write_log_c(const char* db_file) {
fprintf(stderr, "file write error\n");
return false;
}
printf("%s %s %d\n", startdate_local, filename, _data[0]);
printf("%s %d\n", filename, _data[0]);

reset();

Expand Down
2 changes: 1 addition & 1 deletion modules/logger/logger_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def write_log(self):

offset = time.localtime().tm_gmtoff
startdate_local = start_date + datetime.timedelta(seconds=offset)
self.config.G_LOG_START_DATE = startdate_local.strftime("%Y%m%d%H%M%S")
self.config.G_LOG_START_DATE = startdate_local.strftime("%Y-%m-%d_%H-%M-%S")
filename = os.path.join(
self.config.G_LOG_DIR, f"{self.config.G_LOG_START_DATE}.csv"
)
Expand Down
2 changes: 1 addition & 1 deletion modules/logger/logger_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def write_log_python(self):
################

startdate_local = start_date + timedelta(seconds=offset)
self.config.G_LOG_START_DATE = startdate_local.strftime("%Y%m%d%H%M%S")
self.config.G_LOG_START_DATE = startdate_local.strftime("%Y-%m-%d_%H-%M-%S")
filename = os.path.join(
self.config.G_LOG_DIR, f"{self.config.G_LOG_START_DATE}.fit"
)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_write_log(self):
logger = LoggerCsv(config)
result = logger.write_log()
self.assertTrue(result)
self.assertEqual(config.G_LOG_START_DATE, "20230928223913")
self.assertEqual(config.G_LOG_START_DATE, "2023-09-28_22-39-13")


class TestLoggerFit(unittest.TestCase):
Expand All @@ -27,7 +27,7 @@ def test_write_logs(self):
logger = LoggerFit(config)
result = logger.write_log_cython()
self.assertTrue(result)
self.assertEqual(config.G_LOG_START_DATE, "20230928223913")
self.assertEqual(config.G_LOG_START_DATE, "2023-09-28_22-39-13")

filename = f"{config.G_LOG_DIR}/{config.G_LOG_START_DATE}.fit"

Expand All @@ -36,7 +36,7 @@ def test_write_logs(self):

result = logger.write_log_python()
self.assertTrue(result)
self.assertEqual(config.G_LOG_START_DATE, "20230928223913")
self.assertEqual(config.G_LOG_START_DATE, "2023-09-28_22-39-13")

with open(filename, "rb") as f:
python_data = f.read()
Expand Down

0 comments on commit 6ace838

Please sign in to comment.