DurationCalculator - グローバル

  • リリースバージョン: Yokohama
  • 更新日 2025年01月30日
  • 所要時間:17分
  • DurationCalculator スクリプトインクルードは、期間と期日を計算するためのメソッドを提供します。

    DurationCalculator - D

    DurationCalculator クラスのコンストラクタ。

    表 : 1. パラメーター
    名前 タイプ 説明
    なし
    var dc = new DurationCalculator();

    DurationCalculator - calcDuration(数値 seconds)

    現在の開始日時と渡された期間 (秒数) に基づいて終了日時を計算します。

    このメソッドはまた、this.endDateTimethis.seconds、および this.totalSeconds プロパティに、更新された値を設定します。secondsプロパティは、作業スケジュールに基づく期間に実行される作業の合計秒数を表します。totalSeconds プロパティは、作業と非作業の両方を含む、期間の開始時刻と終了時刻の間の合計秒数を表します。

    このメソッドを呼び出す前に、期間に使用する開始時間を指定して setStartDateTime() を呼び出す必要があります。

    表 : 2. パラメーター
    名前 タイプ 説明
    番号 終了日時、秒数、および合計秒数の値を計算するために開始日時に追加する秒数です。
    表 : 3. 返される内容
    タイプ 説明
    ブーリアン 入力値が数値でない場合は False です。
    var gdt = new GlideDateTime("2020-05-01 00:00:00");
    
    var dc = new DurationCalculator();
    dc.setStartDateTime(gdt);
    
    if(!dc.calcDuration(2*24*3600)){ // 2 days
      gs.log("*** Error calculating duration");
      return;
    }
    var secs = dc.getSeconds();
    var totalSecs = dc.getTotalSeconds();
    
    gs.print("***SCHEDULE DURATION: SECS=" + secs + " TOTALSECS=" + totalSecs + " ENDTIME = " + endDateTime);

    出力

    ***SCHEDULE DURATION: SECS=172800 TOTALSECS=970534 ENDTIME = 2020-05-03 00:00:00

    DurationCalculator - calcRelativeDueDate(GlideDateTime start, 数値 days, 文字列 endTime)

    渡された開始時刻に、現在のスケジュールとタイムゾーンを使用して日数を追加し、期日を計算します。

    calcRelativeDuration()によって開始された相対的な継続時間の定義から、calculator.calcRelativeDueDate(calculator.startDateTime, days)として呼び出されます。作業の期日が判定されると、このメソッドは渡されたその日の endTime に時刻を設定します。スケジュールに十分な日数が残っていない場合は、スケジュールの最終日を使用します。

    表 : 4. パラメーター
    名前 タイプ 説明
    start GlideDateTime 計算のための開始日を含む GlideDateTime オブジェクトです。
    番号 開始日に追加する日数です。
    endTime 文字列 計算される期日における作業の完了期限の時刻です。

    空白の場合、デフォルトで作業日の終わりになります。

    形式:HH:mm:ss

    表 : 5. 返される内容
    タイプ 説明
    ブーリアン 完了日がスケジュールの範囲内かどうかを示すフラグです。
    可能な値:
    • true:完了日はスケジュールの範囲内です。
    • false:完了日はスケジュールの範囲外です。このメソッドを呼び出す前にスケジュールが設定されていない場合は未定義です。
    var dc = new DurationCalculator();
    var startTime = new GlideDateTime();
    
    // Settings for calculations
    // Optional: Specify the schedule to use for the following calculations
    dc.setSchedule('08fcd0830a0a0b2600079f56b1adb9ae'); 
    // Optional: Specify a different timezone to use
    dc.setTimeZone("Los Angeles");
    // Optional: Set a start date and time, otherwise the current time is assumed
    dc.setStartDateTime("2020-04-10 08:00:00")
    // Calculate end time, from number of seconds required in the schedule
    dc.calcDuration(3*24*3600); // 3 days
    dc.calcRelativeDueDate(startTime, "3", "07:00:00");

    DurationCalculator - calcRelativeDuration(String relativeDurationID)

    指定された相対期間スクリプトを使用して期間を計算します。

    完了すると、 this.endDateTime そして this.seconds プロパティは、計算の結果を示すように設定されます。

    表 : 6. パラメーター
    名前 タイプ 説明
    relativeDurationID 文字列 相対持続時間スケジュールの sys_id (table cmn_relative_duration)
    表 : 7. 戻り値
    タイプ 説明
    ブーリアン duration スクリプトの結果
    var dc = new DurationCalculator();
    dc.calcRelativeDuration('08fcd0830a0a1b2600074f56b1ad7cb');

    DurationCalculator - calcScheduleDuration(文字列 startTime, 文字列 endTime)

    指定済みのスケジュールの範囲内の startTimeendTime の間の期間と、オプションで上書きされたタイムゾーンを返します。

    このメソッドはまた、現在のスケジュールオブジェクトに this.endDateTimethis.seconds、および this.totalSeconds を設定します。

    表 : 8. パラメーター
    名前 タイプ 説明
    startTime 文字列 オプション。終了時刻の表示値です。

    デフォルト:現在の日時 (setStartDateTime() を使用して設定) が使用されます。このパラメーターを渡さない場合は、dur.calcScheduleDuration("", endDateTime); などのプレースホルダーを渡す必要があります。

    endTime 文字列 オプション。開始時刻の表示値です。

    デフォルト:現在の日時 (setEndDateTime() を使用して設定) を使用します 。

    表 : 9. 返される内容
    タイプ 説明
    番号 スケジュール期間です。endTimestartTime の前である場合は 0 を返します。

    単位:秒

    var dur = new DurationCalculator();
    
    // Set 9-5 weekday schedule. This is the schedule in which endDateTime, seconds, and totalseconds is set
    dur.setSchedule('08fcd0830a0a0b2600079f56b1adb9ae');
    dur.calcScheduleDuration("2019-01-02 11:00:00", "2019-01-06 09:00:00");
    var secs = dur.getSeconds();
    var totalSecs = dur.getTotalSeconds();
    var endDateTime = dur.getEndDateTime() + "";
    
    gs.print("***SCHEDULE DURATION: SECS=" + secs + " TOTALSECS=" + totalSecs + " ENDTIME = " + endDateTime);

    出力

    ***SCHEDULE DURATION: SECS=97200 TOTALSECS=338400 ENDTIME = 2019-01-06 09:00:00

    DurationCalculator - calcScheduleDuration(GlideDateTime startTime, GlideDateTime endTime)

    指定済みのスケジュールの範囲内の startTimeendTime の間の期間と、オプションで上書きされたタイムゾーンを返します。

    このメソッドはまた、現在のスケジュールオブジェクトに this.endDateTimethis.seconds、および this.totalSeconds を設定します。

    表 : 10. パラメーター
    名前 タイプ 説明
    startTime GlideDateTime オプション。使用する開始時刻を含む GlideDateTime オブジェクトです。

    デフォルト:現在の日時 (setStartDateTime() を使用して設定) が使用されます。このパラメーターを渡さない場合は、dur.calcScheduleDuration("", endDateTime); などのプレースホルダーを渡す必要があります。

    endTime GlideDateTime オプション。使用する終了時刻を含む GlideDateTime オブジェクトです。

    デフォルト:現在の日時 (setEndDateTime() を使用して設定) を使用します 。

    表 : 11. 返される内容
    タイプ 説明
    番号 スケジュール期間です。endTimestartTime の前である場合は 0 を返します。

    単位:秒

    var startDateTime = new GlideDateTime("2020-11-02 11:00:00");
    // Instantiate a new GlideDateTime object which has the end date as the current date and time
    var endDateTime = new GlideDateTime(); 
    var dur = new DurationCalculator();
    
    // Set 9-5 weekday schedule. This is the schedule in which endDateTime, seconds, and totalseconds is set
    dur.setSchedule('08fcd0830a0a0b2600079f56b1adb9ae'); 
    dur.calcScheduleDuration(startDateTime, endDateTime);
    var secs = dur.getSeconds();
    var totalSecs = dur.getTotalSeconds();
    
    gs.print("***SCHEDULE DURATION: SECS=" + secs + " TOTALSECS=" + totalSecs + " ENDTIME = " + endDateTime);

    出力

    ***SCHEDULE DURATION: SECS=293734.24 TOTALSECS=970534 ENDTIME = 2020-11-13 16:35:34

    DurationCalculator -

    期間の終了日時を示す、calcDuration/calcRelativeDuration によって設定された endDateTime プロパティを取得します。

    表 : 12. パラメーター
    名前 タイプ 説明
    なし
    表 : 13. 返される内容
    タイプ 説明
    GlideDateTime 終了時刻
    var dc = new DurationCalculator();
    dc.calcDuration(52);
    gs.print(dc.getEndDateTime());

    2012-04-17 20:57:27

    DurationCalculator - getSeconds( )

    期間中に実行される作業の合計秒数を示す、calcDuration/calcRelativeDuration によって設定された this.seconds プロパティを返します。

    これは、開始時間と終了時間の合計時間ではなく、合計作業時間であり、作業時間のパーセンテージを決定するために使用されます。

    表 : 14. パラメーター
    名前 タイプ 説明
    なし
    表 : 15. 返される内容
    タイプ 説明
    番号 総作業時間(秒単位)
    var startDateTime = new GlideDateTime("2020-11-02 11:00:00");
    // Instantiate a new GlideDateTime object which has the end date as the current date and time
    var endDateTime = new GlideDateTime(); 
    var dur = new DurationCalculator();
    
    // Set 9-5 weekday schedule. This is the schedule in which endDateTime, seconds, and totalseconds is set
    dur.setSchedule('08fcd0830a0a0b2600079f56b1adb9ae'); 
    dur.calcScheduleDuration(startDateTime, endDateTime);
    var secs = dur.getSeconds();
    var totalSecs = dur.getTotalSeconds();
    
    gs.print("***SCHEDULE DURATION: SECS=" + secs + " TOTALSECS=" + totalSecs + " ENDTIME = " + endDateTime);

    出力

    ***SCHEDULE DURATION: SECS=293734.24 TOTALSECS=970534 ENDTIME = 2020-11-13 16:35:34

    DurationCalculator - getTotalSeconds( )

    calculate(record) の呼び出しによって設定された totalSeconds 値を返します。

    totalSeconds プロパティは、作業と非作業の両方を含む、期間の開始時刻と終了時刻の間の合計秒数を表します。

    表 : 16. パラメーター
    名前 タイプ 説明
    なし
    表 : 17. 返される内容
    タイプ 説明
    番号 合計秒数
    var startDateTime = new GlideDateTime("2020-11-02 11:00:00");
    // Instantiate a new GlideDateTime object which has the end date as the current date and time
    var endDateTime = new GlideDateTime(); 
    var dur = new DurationCalculator();
    
    // Set 9-5 weekday schedule. This is the schedule in which endDateTime, seconds, and totalseconds is set
    dur.setSchedule('08fcd0830a0a0b2600079f56b1adb9ae'); 
    dur.calcScheduleDuration(startDateTime, endDateTime);
    var secs = dur.getSeconds();
    var totalSecs = dur.getTotalSeconds();
    
    gs.print("***SCHEDULE DURATION: SECS=" + secs + " TOTALSECS=" + totalSecs + " ENDTIME = " + endDateTime);

    出力

    ***SCHEDULE DURATION: SECS=293734.24 TOTALSECS=970534 ENDTIME = 2020-11-13 16:35:34

    DurationCalculator - isAfter(GlideDateTime dt、String tm)

    渡された時刻を、GlideDateTime オブジェクトに渡された時刻値と比較します。

    表 : 18. パラメーター
    名前 タイプ 説明
    dt GlideDateTime または文字列 渡された tm 値と比較する、GlideDateTime オブジェクトまたは日時の表示値のいずれかです。日時の表示値を渡した場合、メソッドはその値を GlideDateTime オブジェクトに変換します。
    tm 文字列 GlideDateTime オブジェクトの時刻値と比較する時刻の表示値です。同じ日付であるという前提です。

    形式:HH:mm:ss

    表 : 19. 返される内容
    タイプ 説明
    ブーリアン 渡された時刻値 (tm) が GlideDateTime オブジェクト (dt) の時刻の後かどうかを示すフラグです。
    可能な値:
    • true:tmdt の後です。
    • false:tmdt の後ではありません。
    var dc = new DurationCalculator();
    gs.print(dc.isAfter("2020-04-10 08:00:00", "09:00:00"));

    ***スクリプト:true

    DurationCalculator - setSchedule(String schedId、String timezone)

    期日の計算に使用するスケジュールとタイムゾーンを設定します。

    表 : 20. パラメーター
    名前 タイプ 説明
    schedId 文字列 設定するスケジュールの sys_id です。

    テーブル:スケジュール [cmn_schedule]。

    タイムゾーン 文字列 オプション。設定するタイムゾーンです。

    デフォルト:ユーザーのタイムゾーンです。

    表 : 21. 返される内容
    タイプ 説明
    なし

    次のコード例は、このメソッドを呼び出す方法を示しています。

    var startDateTime = new GlideDateTime("2020-11-02 11:00:00");
    // Instantiate a new GlideDateTime object which has the end date as the current date and time
    var endDateTime = new GlideDateTime(); 
    var dur = new DurationCalculator();
    
    // Set 9-5 weekday schedule. This is the schedule in which endDateTime, seconds, and totalseconds is set
    dur.setSchedule('08fcd0830a0a0b2600079f56b1adb9ae'); 
    dur.calcScheduleDuration(startDateTime, endDateTime);
    var secs = dur.getSeconds();
    var totalSecs = dur.getTotalSeconds();
    
    gs.print("***SCHEDULE DURATION: SECS=" + secs + " TOTALSECS=" + totalSecs + " ENDTIME = " + endDateTime);

    出力:

    ***SCHEDULE DURATION: SECS=293734.24 TOTALSECS=970534 ENDTIME = 2020-11-13 16:35:34

    DurationCalculator - setStartDateTime(文字列 start)

    期間計算のための開始日時を設定します。

    表 : 22. パラメーター
    名前 タイプ 説明
    開始 文字列 後続の計算のための開始時刻 (GMT) の表示値です。
    表 : 23. 返される内容
    タイプ 説明
    なし
    var dc = new DurationCalculator();
    dc.setStartDateTime("2020-04-10 08:00:00")

    DurationCalculator - setStartDateTime(GlideDateTime description)

    期間計算のための開始日時を設定します。

    表 : 24. パラメーター
    名前 タイプ 説明
    説明 GlideDateTime 後続の計算のための開始時刻 (GMT) を含む GlideDateTime オブジェクトです。
    表 : 25. 返される内容
    タイプ 説明
    なし
    var startDateTime = new GlideDateTime("2020-11-02 11:00:00"); 
    var dur = new DurationCalculator();
    
    // Set 9-5 weekday schedule.
    dur.setSchedule('08fcd0830a0a0b2600079f56b1adb9ae'); 
    dur.setStartDateTime(startDateTime);

    DurationCalculator - setTimeZone(String timezone)

    期日の計算に使用するタイムゾーンを設定します。

    表 : 26. パラメーター
    名前 タイプ 説明
    タイムゾーン 文字列 タイムゾーンの値
    表 : 27. 返される内容
    タイプ 説明
    なし
    var dc = new DurationCalculator();
    dc.setTimeZone("Los Angeles");