-
Notifications
You must be signed in to change notification settings - Fork 315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed decimal UTC time bug #99
Conversation
fixed vn7n24fzkq#90 floor down value because chart uses hours only
Thanks for your work!! I would like to merge this PR, but maybe we can use |
Never mind, I am just realize that we use I think we can take this PR. I will do some more review later, to check there are no other problems. |
I thought that , utc time 0 , 0.3 , 0.45 in min where 0.6 = 1 So for avoid dealing with 0.5 nunber and 0.3 hour / 30 min i used floor. |
Or we can simply check value after point , 0 / 3 / 45 and update utc accordingly and use floor for default to avoid incorrect utc format |
I prefer this way, but throw an exception when the UTC number is invalid. And like you said, default to using floor. |
You are right, would you like to fix it in this PR? |
Or we can create another issue for this if that need to modify many codes. |
Seting up utc time on chart as well handling offset simple task , but I'm not sure how will you display warning or handle the wrong utc and dont want to lean whole code. I'll handle chart display and utc offset u do something about warning . |
Sounds good to me, thanks! |
By the way, about the warning, I will just throw an exception like this. if(!IsValidUTCTime(utcTime){
throw Exception ("The UTC format is invalid, it should be ......")
} |
const adjustOffset = function (offset: number, RoundRobin: {offset: number}): number {
if (offset % 1 == 0) {
return offset;
// offset % 1 should be 0.3 or 0.7 but its js and it gives 0.29999 or -0.299999 thats why this frankenstein
} else if ((offset % 1 > 0.29 && offset % 1 < 0.31) || (offset % 1 < -0.29 && offset % 1 > -0.31)) {
// toggle up and down between hour
RoundRobin.offset = (RoundRobin.offset + 1) % 2;
return RoundRobin.offset === 0 ? Math.floor(offset) : Math.ceil(offset);
} else if ((offset % 1 > 0.44 && offset % 1 < 0.46) || (offset % 1 < -0.44 && offset % 1 > -0.45)) {
// distrubute 1 : 3 ratio for 0.45 utc time
RoundRobin.offset = (RoundRobin.offset + 1) % 4;
return RoundRobin.offset % 4 == 0 ? Math.floor(offset) : Math.ceil(offset);
} else {
// flood down , if utc is given right it will never be executed
return Math.floor(offset);
}
};
.
.
let RoundRobin = {
offset: 0
};
.
.
chartData[24 + adjustOffset(afterOffset, RoundRobin)] += 1; or use simply this for 0.3 and 0.45 Math.ceil(afterOffset); |
in api IDK how it will display |
I think we can take this code, and after that, we don't need to throw exceptions, tho. |
We don't care about the error display here, just throw an exception. And |
@SauravDharwadkar Thanks for your hard work! Are you still working on this? |
was busy . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
I left some comments here, take a look, please.
@@ -39,10 +57,14 @@ const getProductiveTimeData = async function (username: string, utcOffset: numbe | |||
// process productiveTime | |||
const chartData = new Array(24); | |||
chartData.fill(0); | |||
// eslint-disable-next-line prefer-const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If possible, I think we should avoid disabling the eslint
here. Could we do that? 🤔
@@ -39,10 +57,14 @@ const getProductiveTimeData = async function (username: string, utcOffset: numbe | |||
// process productiveTime | |||
const chartData = new Array(24); | |||
chartData.fill(0); | |||
// eslint-disable-next-line prefer-const | |||
let RoundRobin = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use camel case, the first letter should be lowercase.
for (const time of productiveTime.productiveDate) { | ||
const hour = new Date(time).getUTCHours(); // We use UTC+0 here | ||
const afterOffset = Number(hour) + Number(utcOffset); // Add offset to hour | ||
// covert afterOffset to 0-23 | ||
const afterOffset = adjustOffset(Number(hour) + Number(utcOffset), RoundRobin); // Add offset to hour |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you fix this?
I am just quickly google this one.
https://stackoverflow.com/questions/53516594/why-do-i-keep-getting-delete-cr-prettier-prettier
Hi, @SauravDharwadkar. |
You can take over , sorry for late reply busy last couple of months |
Solved in #123 |
fixed #90
floor down value because chart uses hours only