First business day of month

Discuss RoboTask here
Post Reply
Rukbunker
Posts: 192
Joined: Mon Feb 22, 2016 4:06 pm
Location: Netherlands

First business day of month

Post by Rukbunker »

Hey Oleg,

You know my programming skills s**k very hard, and you have recently created a script which determines the last business day of the month in JS Script. You guess it, now it's time to determine the first business day of the month :D
Also in this case it's used to set a variable to "yes" if it's the case.

I was playing around with the offset for a long time, tried another script, and anotherone, but I failed (ofcourse) to get it done. Can you help me out?

This was the code for the last business day (I already renamed the function):

Code: Select all

function FirstBusinessDayOfMonth(year, month) {
var date = new Date();
var offset = 0;
var result = null;

if ('undefined' === typeof year || null === year) {
year = date.getFullYear();
}

if ('undefined' === typeof month || null === month) {
month = date.getMonth();
}

do {
result = new Date(year, month, offset);

offset--;
} while (0 === result.getDay() || 6 === result.getDay());

return result.getVarDate();
}

//LogMessage(FirstBusinessDayOfMonth(2018, 4))

Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: First business day of month

Post by Oleg »

Use this script

Code: Select all

function FirstBusinessDayOfMonth(year, month)
{
  var date = new Date();
  var offset = 1;
  var result = null;

  if ('undefined' === typeof year || null === year)
  {
    year = date.getFullYear();
  }

  if ('undefined' === typeof month || null === month)
  {
    month = date.getMonth();
  }

  do
  {
    result = new Date(year, month, offset);
    offset++;
  } while (0 === result.getDay() || 6 === result.getDay());
  //while Saturday or Sunday

  return result.getVarDate();
}

//LogMessage(FirstBusinessDayOfMonth(2018, 8))
Also see the example below

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|1075658632
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task513"
Hide=INTEGER|0
ID=INTEGER|-1915200085
LogOnAsUser=INTEGER|1
Name=STRING|"First business day"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER

[Actions\Action1]
ActionID=STRING|"A_SCRIPT_JSEVALUATE"
Enabled=INTEGER|-1
Name=STRING|"JS Evaluate"
Params=FOLDER

[Actions\Action1\Params]
expression=STRING|"FirstBusinessDayOfMonth(2018, 8)"
line00000000=STRING|"function FirstBusinessDayOfMonth(year, month)"
line00000001=STRING|"{"
line00000002=STRING|"  var date = new Date();"
line00000003=STRING|"  var offset = 1;"
line00000004=STRING|"  var result = null;"
line00000006=STRING|"  if ('undefined' === typeof year || null === year)"
line00000007=STRING|"  {"
line00000008=STRING|"    year = date.getFullYear();"
line00000009=STRING|"  }"
line0000000B=STRING|"  if ('undefined' === typeof month || null === month)"
line0000000C=STRING|"  {"
line0000000D=STRING|"    month = date.getMonth();"
line0000000E=STRING|"  }"
line00000010=STRING|"  do"
line00000011=STRING|"  {"
line00000012=STRING|"    result = new Date(year, month, offset);"
line00000013=STRING|"    offset++;"
line00000014=STRING|"  } while (0 === result.getDay() || 6 === result.getDay());"
line00000015=STRING|"  //while Saturday or Sunday"
line00000017=STRING|"  return result.getVarDate();"
line00000018=STRING|"}"
line0000001A=STRING|"//LogMessage(FirstBusinessDayOfMonth(2018, 8))"
linecount=STRING|"27"
loadfromfile=STRING|"1"
variable=STRING|"res"

[Actions\Action2]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER

[Actions\Action2\Params]
message=STRING|"{res}"
type=STRING|"3"
Year - full year
Month - from 0 to 11 (0-January, ..., 11 - December)
Oleg Yershov
Rukbunker
Posts: 192
Joined: Mon Feb 22, 2016 4:06 pm
Location: Netherlands

Re: First business day of month

Post by Rukbunker »

Ofcourse.....so simple. It's working. I saw that only the offset was changed and the increments of it. A programmer will see it straight away, for my brains that will never happen!

Thanks anyway.
Post Reply