Closed jackred closed 4 years ago
All round hours after noon until midnight have the same problem but with the text showing "midnight" instead of "noon". The issue doesn't happen if you set the time format to 24h. Also, 12:01am-12:59am and 12:01pm-12:59pm display as 0:01am-0:59am and 0:01pm-0:59pm respectively.
oups. Never saw this error because I use 24h format most.
The code that does this calculation is a function helpers.minutesToClock
in the napchart
repo.
https://github.com/larskarbo/napchart/blob/master/lib/helpers.js#L135
Here is the function:
helpers.minutesToClock = function (chart, minutes) {
minutes = Math.floor(minutes)
var hours = Math.floor(minutes / 60) + ''
minutes = minutes % 60 + ''
if (hours.length == 1) {
hours = '0' + hours
}
if (minutes.length == 1) {
minutes = '0' + minutes
}
if (chart.config.ampm) {
if (minutes == 0) {
return (hours > 12) ? 'midnight' : 'noon'
}
if(hours < 12){
return (hours*1) + ':' + minutes + ' am'
} else {
return (hours*1 - 12) + ':' + minutes + ' pm'
}
} else {
return hours + ':' + minutes
}
}
This function accepts a minute argument between 0 and 1440.
Anyone wants to have a shot at fixing it?
Try this:
helpers.minutesToClock = function (chart, minutes) {
minutes = Math.floor(minutes)
var hours = Math.floor(minutes / 60) + ''
minutes = minutes % 60 + ''
if (hours.length == 1) {
hours = '0' + hours
}
if (minutes.length == 1) {
minutes = '0' + minutes
}
if (chart.config.ampm) {
if (minutes == 0 && hours % 12 === 0) {
return (hours > 12 || hours == 0) ? 'midnight' : 'noon'
}
if (hours < 12) {
return (((hours*1 + 11) % 12) + 1) + ':' + minutes + ' am'
} else {
return (((hours*1 + 11) % 12) + 1) + ':' + minutes + ' pm'
}
} else {
return hours + ':' + minutes
}
}
@absentabyss don't have time to test right now, but could you create a PR over at https://github.com/larskarbo/napchart?
On the website, any block starting or ending on a round hour (like 08:00 or 15:00) has its time indication written as "noon" instead of the correct time.
There is no problem on the image generated by the api (example: http://thumb.napchart.com:1771/api/getImage?width=600&height=600&chartid=pm88x)