단순 기간 대 상대 기간

  • 릴리스 버전: Yokohama
  • 업데이트 날짜 2025년 01월 30일
  • 읽기8분
  • 작업을 완료하는 데 필요한 작업량은 "상대적 기간"으로 표현할 수 있습니다.

    상대 기간은 시작 시간을 기준으로 예상 기한 날짜 및 시간을 결정합니다. 상대 기간의 예로는 "다음 영업일 오후 4시까지" 또는 "영업일 기준 2일 오전 10시 30분까지" 등이 있습니다.

    상대적 기간을 계산하려면 달력과 시간대를 고려하여 "다음 영업일"이 무엇을 의미하는지 결정해야 하는데, 이는 유효한 근무일을 정의하는 달력이고 시간대도 결과에 영향을 미치기 때문입니다. 예를 들어 "다음 영업일 오후 4시까지"를 고려하십시오.
    • 월요일 오후 12시인 경우: 다음 영업일 오후 4시 = > 화요일 오후 4시
    • 금요일 오후 2시인 경우: 다음 영업일 오후 4시 = 다음 월요일 오후 4시까지 >
    주:
    다음 영업일은 보통 시작 날짜와 시간으로 정의됩니다. 예를 들어, "오후 2시 이전인 경우 다음 영업일 오후 4시"는 현재 시간이 영업일 오후 2시 이후인 경우 "다음 영업일"은 오늘이 계산되지 않으므로 실제로 영업일 기준 2일을 의미합니다.

    단순 기간 계산

    이 비즈니스 규칙 및 스크립트 예제는 단순 기간을 계산하는 방법을 보여 줍니다.

    var dur =new DurationCalculator();
    dur.setSchedule(current.schedule);
    dur.setStartDateTime("");
     
    if(current.duration_type==""){
             dur.calcDuration(current.duration.getGlideObject().getNumericValue()/1000);}else{
             dur.calcRelativeDuration(current.duration_type);}
     
        current.end_date_time= dur.getEndDateTime();
        current.work_seconds= dur.getSeconds();

    이 스크립트는 DurationCalculator를 사용하여 단순 기간을 계산하는 방법을 보여 줍니다.

    /**
     * Sample script demonstrating use of DurationCalculator to compute simple durations
     * 
     */
     
    gs.include('DurationCalculator');
    executeSample();
     
    /**
     * Function to house the sample script.
     */
    function executeSample(){
     
        // First we need a DurationCalculator object.
        var dc =new DurationCalculator();
     
        // Compute a simple duration without any schedule. The arguments
        // can also be of type GlideDateTime, such as fields from a GlideRecord.
        var dur = dc.calcScheduleDuration("5/1/2012","5/2/2012");
        gs.log("calcScheduleDuration no schedule: "+ dur);
        // 86400 seconds (24 hours)
     
        // The above sample is useful in limited cases. We almost always want to 
        // use some schedule in a duration computation, let's load a schedule.
        addSchedule(dc);
     
        // Compute a duration using the schedule. The schedule
        // specifies a nine hour work day. The output of this is 32400 seconds, or
        // a nine hour span.
        dur = dc.calcScheduleDuration("5/23/2012 12:00","5/24/2012 12:00");
        gs.log("calcScheduleDuration with schedule: "+ dur);
        // 32400 seconds (9 hours)
     
        // Compute a duration that spans a weekend and holiday. Even though this
        // spans three days, it only spans 9 work hours based on the schedule.
        dur = dc.calcScheduleDuration("5/25/2012 12:00","5/29/2012 12:00");
        gs.log("calcScheduleDuration with schedule spaning holiday: "+ dur);
        // 32400 seconds (9 hours)
     
        // Use the current date time in a calculation. The output of this is
        // dependent on when you run it.
        var now =new Date();
        dur = dc.calcScheduleDuration("5/15/2012",new GlideDateTime());
        gs.log("calcScheduleDuration with schedule to now: "+ dur);
        // Different on every run.}
     
    /** 
     * Add a specific schedule to the DurationCalculator object.
     *  
     * @param durationCalculator An instance of DurationCalculator
     */
    function addSchedule(durationCalculator){
       //  Load the "8-5 weekdays excluding holidays" schedule into our duration calculator.
       var scheduleName ="8-5 weekdays excluding holidays";
       var grSched =new GlideRecord('cmn_schedule');
       grSched.addQuery('name', scheduleName);
       grSched.query();if(!grSched.next()){
            gs.log('*** Could not find schedule "'+ scheduleName +'"');
            return;}
        durationCalculator.setSchedule(grSched.getUniqueValue());}

    상대 기간 계산

    상대 기간 계산 스크립트의 예입니다.

    이 스크립트는 "오전 10시 이후인 경우 다음 날 오후 4시"의 상대 기간을 계산합니다.
    // Next day at 4pm if before 10am
    var days =1;
    if(calculator.isAfter(calculator.startDateTime,"10:00:00")) 
          days++;
     
    calculator.calcRelativeDueDate(calculator.startDateTime, days,"16:00:00");

    이 스크립트는 DurationCalculator를 사용하여 상대 기간을 계산하는 방법을 보여 줍니다.

    /**
     * Sample use of relative duration calculation.
     * 
     */
     
    gs.include('DurationCalculator');
    executeSample();
     
    /**
     * Function to house the sample script.
     */
    function executeSample(){
     
        // First we need a DurationCalculator object. We will also use
        // the out-of-box relative duration "2 bus days by 4pm"
        var dc =new DurationCalculator();
        var relDur ="3bf802c20a0a0b52008e2859cd8abcf2";
        // 2 bus days by 4pm if before 10am
        addSchedule(dc);
     
        // Since our start date is before 10:00am our result is two days from
        // now at 4:00pm.
        dc.setStartDateTime("5/1/2012 09:00:00");
        if(!dc.calcRelativeDuration(relDur)){
            gs.log("*** calcRelativeDuration failed");
            return;}
        gs.log("Two days later 4:00pm: "+ dc.getEndDateTime());
     
        // Since our start date is after 10:00am our result is three days from
        // now at 4:00pm.
        dc.setStartDateTime("5/1/2012 11:00:00");
        if(!dc.calcRelativeDuration(relDur)){
            gs.log("*** calcRelativeDuration failed");
            return;}
        gs.log("Three days later 4:00pm: "+ dc.getEndDateTime());}
     
    /** 
     * Add a specific schedule to the DurationCalculator object.
     *  
     * @param durationCalculator An instance of DurationCalculator
     */
    function addSchedule(durationCalculator){
      //  Load the "8-5 weekdays excluding holidays" schedule into our duration calculator.
      var scheduleName ="8-5 weekdays excluding holidays";
      var grSched =new GlideRecord('cmn_schedule');
      grSched.addQuery('name', scheduleName);
      grSched.query();
      if(!grSched.next()){
            gs.log('*** Could not find schedule "'+ scheduleName +'"');
            return;}
      durationCalculator.setSchedule(grSched.getUniqueValue(),"GMT");}