JavaScript-a question about the time of absence calculation

Source: Internet
Author: User
Let's start by saying the rules of leave:
1, the Morning leave, the duration shall not be less than 3 hours
2, the afternoon leave, the length shall not be less than 5 hours
3. Working hours: 9:00~18:00
4. One hour of non-working hours at noon
Because of the company's system, overtime does not pay overtime but can be take some, so the time must be accurate to the hour. So here's the question:
1, if I leave the time span is the morning to the afternoon to meet the rules, but the system calculation time will be more than one hour:

    • My solution is: first determine whether the start and time is the same day, and then determine whether the start time is morning, whether the end time is afternoon, if all is satisfied, then the system calculates the time minus one hour

2, if some people silly, choose start and end time beyond the working time, such as the end time is after 18:00, then also determine whether to deduct the time after 18:00

3, the most troublesome is the cross-day, if the holiday contains legal holidays, double break and other special circumstances. There are non-integers across the day, such as only three days after the 11 o'clock in the morning, then three days after the 0:00~9:00 this period how to remove

Thoughts some confusion, also please have experienced predecessors to share experience, thank you!!

Reply content:

Let's start by saying the rules of leave:
1, the Morning leave, the duration shall not be less than 3 hours
2, the afternoon leave, the length shall not be less than 5 hours
3. Working hours: 9:00~18:00
4. One hour of non-working hours at noon
Because of the company's system, overtime does not pay overtime but can be take some, so the time must be accurate to the hour. So here's the question:
1, if I leave the time span is the morning to the afternoon to meet the rules, but the system calculation time will be more than one hour:

    • My solution is: first determine whether the start and time is the same day, and then determine whether the start time is morning, whether the end time is afternoon, if all is satisfied, then the system calculates the time minus one hour

2, if some people silly, choose start and end time beyond the working time, such as the end time is after 18:00, then also determine whether to deduct the time after 18:00

3, the most troublesome is the cross-day, if the holiday contains legal holidays, double break and other special circumstances. There are non-integers across the day, such as only three days after the 11 o'clock in the morning, then three days after the 0:00~9:00 this period how to remove

Thoughts some confusion, also please have experienced predecessors to share experience, thank you!!

Cross-day, in fact, and the day, no difference, anyway, the time to leave every day is 9 to 18 points
First Judge
(Start-to-end)/(24x3600) = number of days, if greater than 1, the description is cross-day, such as: 2016-08-30 10:30-2016-09-04 12:00, in fact, as long as the calculation of 08-30 and 09-04 two days of the situation is good, the middle of those days 7*3=21 hours

One day (work + leave)
There are only a few cases, morning leave, afternoon leave, morning to the afternoon
The IF condition will be a bit of a hassle.

End time <= 12, morning leave.
Start time >= 13 && end Time <= 18 pm leave

The rest of the basic is the cross-section, the Cross-section of the morning and afternoon to calculate the good.

0-9,12-13,18-0 the time period, there is the intersection of the part does not calculate just fine

你首先需要一个排班表用于判断是否是工作日。如果小于9点,=9点,大于18点=18点,再用你1里面说的方法不久完了。
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.