Date, Get Weekend Sunday
Date, Get Weekend Sunday
Gets weekend Sundays of any date. If Sunday is specified, that day itself will be returned. If you want to get “Monday of the next week” or “Tuesday of the current week”, you need to convert like #q_date.addDays(1) or #q_date.addDays(-5).
Configs
  • A: Set Original Date/Datetime (eg “2022-04-29” ) *#{EL}
  • B: Select DATE DATA that stores Weekend Sunday (update) *
Script (click to open)
// GraalJS Script (engine type: 2)

//////// START "main()" /////////////////////////////////////////////////////////////////
main();
function main(){ 

//// == Config Retrieving / 工程コンフィグの参照 ==
const strTarget       = configs.get( "StrConfA" );        /// REQUIRED /////////////
  if( strTarget     === "" ){
    throw new Error( "\n AutomatedTask ConfigError:" +
                     " Config {A: Date or Datetime} is empty \n" );
  }
  let dateTarget      = parseDateAsMidnight( strTarget );
const datePocketOutput = configs.getObject( "SelectConfB" ); /// REQUIRED ///////////


//// == Data Retrieving / ワークフローデータの参照 ==
// (Nothing. Retrieved via Expression Language in Config Retrieving)


//// == Calculating / 演算 ==
let numDayId = dateTarget.getDay(); // Sun=0, Mon=1 ,,
if( numDayId !== 0 ){
  let numUntilSunday = ( 7 - numDayId );
  dateTarget.setDate( dateTarget.getDate() + numUntilSunday );
}


//// == Data Updating / ワークフローデータへの代入 ==
engine.setData( datePocketOutput, new java.sql.Date( dateTarget.getTime() ) );


} //////// END "main()" /////////////////////////////////////////////////////////////////


function parseDateAsMidnight( str ) { // Transform date from String to Date
  if( str === "" ){
    throw new Error( "\n AutomatedTask ParseDateError:" +
                     " String is empty \n" );
  }
  var arrNumParts = str.match( /\d+/g );
  if( arrNumParts === null ){
    throw new Error( "\n AutomatedTask ParseDateError:" +
                     " No numeric characters in: " + str + "\n" );
  }
  if( arrNumParts.length < 3){
    throw new Error( "\n AutomatedTask ParseDateError:" +
                     " 3 Parts of numeric characters are needed in: " + str + "\n" );
  }
  return new Date( parseInt(arrNumParts[0], 10), 
                   parseInt(arrNumParts[1], 10) - 1, 
                   parseInt(arrNumParts[2], 10) ); // months are 0-based
  // Note: new Date("2014-11-10") // Mon Nov 10 2014 09:00:00 GMT+0900 (JST)
  // Note: new Date(2014, 10, 10) // Mon Nov 10 2014 00:00:00 GMT+0900 (JST)
}

/*

Notes:
- When the process reaches the automated task, the DATE data is automatically calculated.
    - `YYYY-MM-DD` (date type format), `YYYY/MM/DD`, etc.
    - `YYYY-MM-DD hh:mm` (datetime data format) can also be regarded as the starting date.
APPENDIX:
- Update Data
    - eg. Last day of the previous month
    - `#today.addMonths(-1).getLastDateInMonth()`
    - https://support.questetra.com/bpmn-icons/service-task-data-assignment/
- R2271: Output of Date and Datetime Data via EL syntax
    - https://questetra.zendesk.com/hc/en-us/articles/360024292672-R2271

Notes-ja:
- 案件が自動処理工程に到達した際、日付データについて自動計算されます。
    - `YYYY-MM-DD` (日付型データの書式) や `YYYY/MM/DD` など
    - `YYYY-MM-DD hh:mm` (日時型データの書式) も起点日と見なすことが可能です。
APPENDIX-ja:
- データ更新
    - 例 "前月の末日"
    - `#today.addMonths(-1).getLastDateInMonth()`
    - https://support.questetra.com/ja/bpmn-icons/service-task-data-assignment/
- R2271: EL式による日付日時としての出力(データ設定式)
    - https://questetra.zendesk.com/hc/ja/articles/360024292672-R2271
*/

Download

2021-10-01 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/date-get-weekend-sunday-2021/
The Add-on import feature is available with Professional edition.
Freely modifiable JavaScript (ECMAScript) code. No warranty of any kind.

Notes

  • When the process reaches the automated task, the DATE data is automatically calculated.
    • YYYY-MM-DD (date type format), YYYY/MM/DD, etc.
    • YYYY-MM-DD hh:mm (datetime data format) can also be regarded as the starting date.

Capture

Gets weekend Sundays. If Sunday is specified, that day itself will be returned. If you want to get "Monday of the next week" or "Tuesday of the current week", you need to convert like #q_date.addDays(1) or #q_date.addDays(-5).
Gets weekend Sundays. If Sunday is specified, that day itself will be returned. If you want to get "Monday of the next week" or "Tuesday of the current week", you need to convert like #q_date.addDays(1) or #q_date.addDays(-5).

Appendix

See also

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: