Skip to content

Commit 19a90a3

Browse files
committed
fix bug in X axis timezone
1 parent 62ab7aa commit 19a90a3

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

CHANGELOG.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
3.7.dev
22
-------
33
- It is not longer required for the prefix in userStatusLines to end with a ":".
4+
- Fixed a bug which could cause the wrong time range to be selected for the x axis if the analyzer was run in a different timezone from the timezone where the HTML is viewed.
45

56
3.6
67
---

apamax/log_analyzer.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -1847,10 +1847,14 @@ def writeOverviewHTMLForAllFiles(self, overviewHTML, **extra):
18471847

18481848
# zoom to show everything
18491849
times = [f.get('startTime') for f in self.files]+[f.get('endTime') for f in self.files]
1850-
times = sorted([t.timestamp() for t in times if t])
1850+
times = sorted([t for t in times if t])
18511851
if len(times) >= 2:
1852+
times = [min(times), max(times)]
18521853
defaultoptions['dateWindow'] = [
1853-
int(1000*min(times)), int(1000*max(times))
1854+
f"new Date({dt.year},{dt.month-1},{dt.day},{dt.hour},{dt.minute},{dt.second})"
1855+
#1000*dt.timestamp()
1856+
for dt in times
1857+
#int(1000*min(times)), int(1000*max(times))
18541858
]
18551859

18561860
with io.open(os.path.join(self.outputdir, 'overview.html'), 'w', encoding='utf-8') as out:
@@ -1937,7 +1941,8 @@ def writeOverviewHTMLForAllFiles(self, overviewHTML, **extra):
19371941
with io.open(tmpfile, 'r', encoding='utf-8') as datafile:
19381942
shutil.copyfileobj(datafile, out)
19391943
os.remove(tmpfile)
1940-
out.write('],\n'+json.dumps(options)[:-1]+',"legendFormatter":legendFormatter}'+'\n);\n')
1944+
# this regex converts a JavaScript string containing new Date(...) to a proper JavaScript object
1945+
out.write('],\n'+re.sub('"(new [^"]*)"', "\\1", json.dumps(options)[:-1])+',"legendFormatter":legendFormatter}'+'\n);\n')
19411946
out.write('\ncharts.push(g);\n')
19421947
if c == 'rates':
19431948
for a in file['annotations']:

0 commit comments

Comments
 (0)