Hi
How can I make a flow with one input folder and 7 output folders, the files that comes true the flow must output in a current name of the day.
Files comming in on Monday lands in Monday folder and files enters Tuesday coming Tuesday folder etc.
René
Filter on weekday
Re: Filter on weekday
Hi Jarmer,
It would be nice if Switch's Switch.Date supported Week Dates, but it does not. That would give you a number from 1-7 corresponding to Monday-Sunday.
So I think what I would do to make this work is to write a script to resolve the current day of the week using the Date() class with the getDay() method and write that to private data.
If you do not have access to the scripting module, then perhaps you can using the "Execute command" flow element to run something like this which will return the full day of the week:
You could then route your files to the 7 folders based on that response.
Please refrain from posting duplicate questions on the forum.
It would be nice if Switch's Switch.Date supported Week Dates, but it does not. That would give you a number from 1-7 corresponding to Monday-Sunday.
So I think what I would do to make this work is to write a script to resolve the current day of the week using the Date() class with the getDay() method and write that to private data.
Code: Select all
var d = new Date();
var day_of_the_week = d.getDay();
Code: Select all
date '+%A'
Please refrain from posting duplicate questions on the forum.
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
Re: Filter on weekday
Hi Gabrielp,
I'm not that good to script, but I have treid this, unsuccessfully, can you see the error ?:
var d = new Date();
var day_of_the_week = d.getDay();
var day_of_the_weekValue = 0;
{
switch (day_of_the_week) {
case "Monday":
day_of_the_weekValue =1;
break;
default:
day_of_the_weekValue;
}
}
day_of_the_weekValue;
I'm not that good to script, but I have treid this, unsuccessfully, can you see the error ?:
var d = new Date();
var day_of_the_week = d.getDay();
var day_of_the_weekValue = 0;
{
switch (day_of_the_week) {
case "Monday":
day_of_the_weekValue =1;
break;
default:
day_of_the_weekValue;
}
}
day_of_the_weekValue;
Re: Filter on weekday
Code: Select all
function jobArrived( s : Switch, job : Job )
{
var d = new Date();
var day_of_the_week = d.getDay();
job.setPrivateData( 'ProccessWeekDate', day_of_the_week );
job.sendToSingle( job.getPath() );
}
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
Re: Filter on weekday
Hi Again,
I still have problems with this, I can not get it to work.
But I have found another solution.
I will use the "Set hierarchy parth", with "single-line text with variables defined", using " [Switch.Date:Format="dddd",TimeZone="UTC"].
This will give me a weekday in "Archive hierachy".
I still have problems with this, I can not get it to work.
But I have found another solution.
I will use the "Set hierarchy parth", with "single-line text with variables defined", using " [Switch.Date:Format="dddd",TimeZone="UTC"].
This will give me a weekday in "Archive hierachy".
Re: Filter on weekday
Very good to knew!Jarmer wrote:Hi Again,
I still have problems with this, I can not get it to work.
But I have found another solution.
I will use the "Set hierarchy parth", with "single-line text with variables defined", using " [Switch.Date:Format="dddd",TimeZone="UTC"].
This will give me a weekday in "Archive hierachy".
I have not tested 3 or 4 "d".
3 gives "Fri"
4 gives "Friday"
Between jobs!
Re: Filter on weekday
That's an excellent workaround to actually get the weekday. It even returns the name of the day depending on the language your system is running, so I get the names in Danish 
I have another case, where I need to sort files on week-numbers. ISO 8601 does mention using W to retrieve the week-number, but it doesn't seem to be implemented in Switch.date. Does anyone have a solution for this?

I have another case, where I need to sort files on week-numbers. ISO 8601 does mention using W to retrieve the week-number, but it doesn't seem to be implemented in Switch.date. Does anyone have a solution for this?
Re: Filter on weekday
Week numbers are more complicated than you would think. For example, if January 1st is a Friday (as in 2016), then everything up until January 3rd is actually the last week of the previous year. The first week of that year doesn't start until January 4th (the first Monday). But if January 1st is a Thursday (as in 2015), then December 29th, 30th and 31st are all part of week 1. Confused yet?
The rule is actually rather simple: the first week is the one with more than half its days in the new year.
That is the official (ISO) version anyway. Some people want a different algorithm, where the first week of the year is always the first *full* week. And then some people want the week to start on Monday, others on Sunday. It's all a big mess.
So the first thing to do is decide exactly what you want: the official ISO way, or something else. Once you know that, you'll probably need some scripting, because I don't think the built-in date objects in Switch have functionality to get the week number.

That is the official (ISO) version anyway. Some people want a different algorithm, where the first week of the year is always the first *full* week. And then some people want the week to start on Monday, others on Sunday. It's all a big mess.
So the first thing to do is decide exactly what you want: the official ISO way, or something else. Once you know that, you'll probably need some scripting, because I don't think the built-in date objects in Switch have functionality to get the week number.
Re: Filter on weekday
I'm fully aware of the different ways of counting week numbers, but since there is an ISO-standard I see no reasons not to stick to that.
Re: Filter on weekday
Good to hear; imo too many people cling to their regional traditions instead of adopting a common standard.Terkelsen wrote:I'm fully aware of the different ways of counting week numbers, but since there is an ISO-standard I see no reasons not to stick to that.
Code: Select all
var theNow = new Date(); // or a test date
var theYear = theNow.getYear();
var theWeek = -1; // initialise to an invalid number
// some helpful "special" days
var theDec31st = new Date( theYear, 12, 31 );
var theJan1st = new Date( theYear, 1, 1 );
// special case for the last 3 days of the last week
if ( theNow.getMonth() == 12 && theNow.getDate() > 28
&& theDec31st.getDay() < 4 && theNow.getDay() <= theDec31st.getDay() )
{
// if Dec 31st is a Monday, Tuesday or Wednesday
// and today is still in the same week, we're already
// in the first week of the next year.
++theYear;
theWeek = 1;
}
else // all other cases: calculate week number based on days passed since first week
{
// special case for the first 3 days of the first week
if ( theNow.getMonth() == 1 && theNow.getDate() < 4 )
{
// if Jan 1st is a Friday, Saturday or Sundsy, and today is
// still in the same week, we're still in the last week
// of the previous year.
if ( theJan1st.getDay() > 4 && theNow.getDay() >= theJan1st.getDay() )
{
theNow = new Date( --theYear, 12, 31 );
// also fix the Jan 1st that we use as reference
theJan1st = new Date( theYear, 1, 1 );
}
}
// the actual calculation: the number of days between today and Jan 1st,
// divided by 7, and rounded up.
theWeek = Math.ceil((1+(theNow.getTime() - theJan1st.getTime())/1000/60/60/24)/7);
}