Hello,ramil!
I have a problem with the accuracy of the time calculation. For example, if I input a 1.5 hour period and calculate the end date, my start date is 2023-2-18,8:00, the duration is in hours, but the end date is finally calculated to me as 2023-2-19,0:0. In addition, 2023-2-18 is a special date, the working hours are [9:30-12:00]; May I ask if the decimal number will be automatically rounded off when the duration unit is hours, and the schedule will be discarded?
Hello,
Gantt stores the duration in the integer format. There is no way to change that. If you set a decimal duration, only the integer part will remain. The duration will be rounded depending on the duration_unit parameter: https://docs.dhtmlx.com/gantt/api__gantt_duration_unit_config.html
If it is “day” (default), it will be 0. For “hour”, it will be 2 hours.
Here is an example (check task #4): https://snippet.dhtmlx.com/9suelbar
Hello!ramil.
Thank you for your reply. However, I am sorry that I may not have expressed it clearly before. The specific question is as follows:
According to the normal calculation result, the result should be 2023-2-189:30, but the final result is unexpected. The final calculation result is Sat Feb 11 2023 00:00:00 GMT+0800 (Chinese standard time).
The general method is as follows:
Looking forward to your reply!
Hello,
If you specify a decimal value in the calculateEndDate method, it will not work as you expect. As I said before, Gantt cannot work with decimal values internally. The decimal part will be removed. Moreover, the string format should not be used in that method as it expects the Date object as the first parameter or the start_date parameter: https://docs.dhtmlx.com/gantt/api__gantt_calculateenddate.html
You will get an error if you try to pass a string:
Then you can use the returned value in the calculateEndDate method. But you need to use the “minute” unit to convert the duration value and not round it to hours. Otherwise, you will get 2 hours.
Hello,ramil!
Sorry to bother you again, I got another question here, which is the “getClosestWorkTime” method, which I find a little weird.
For example:
The method invocation is shown in the figure above, but the result is somewhat unexpected:
Could you please explain the logic of this method? Thank you!
Looking forward to your reply
Hello,
The getClosestWorkTime method obtains the working time that is closest to the provided date.
The difference between 17:00 and 24:00 is 7, while the difference between 24:00 and 08:00 is 8. So, it is expected that Gantt chooses 17:00.
You may think that the closest working time to the left side would be 16:00, but there is 1 working hour between 16:00 and 17:00. As at 17:00 the working time starts (if you calculate the dates from right to left), Gantt chooses this hour.
If you want to obtain the closest working time in the future, you need to specify the direction in the dir parameter.