It's a similar problem as the other topic "Filter on Weekday" (http://forum.enfocus.com/viewtopic.php?f=13&t=1162). But I have a date in one xml-file in the format "yyyyMMddHHmm" (201510091437).
I want to convert that to is corresponding weekday. Eg. Friday as the example.
Can I get it to work with "Set hierarch path" it would be great.
Is it possible?
Convert Metadata field (Date) to Weekday
Convert Metadata field (Date) to Weekday
Between jobs!
Re: Convert Metadata field (Date) to Weekday
This should do it:
Code: Select all
var getDay = function( dateString, debug )
{
debug = typeof debug !== 'undefined' ? debug : false;
// Pattern for parsing the string
var regex = /(\d{4})+(\d{2})+(\d{2})+(\d{2})+(\d{2})/;
regex.search(dateString);
var parsedYear = regex.cap(1);
var parsedMonth = regex.cap(2);
var parsedDay = regex.cap(3);
var parsedHour = regex.cap(4);
var parsedMinute = regex.cap(5);
// Log
if(debug == true) s.log(2, parsedYear + ', ' + parsedMonth + ', ' + parsedDay + ', ' + parsedHour + ', ' + parsedMinute);
// Convert to date
var date = new Date( parsedYear, parsedMonth, parsedDay, parsedHour, parsedMinute );
// Get the day of the week
var day = date.getDay();
// Convert day code to full day
var weekDayValues = {
1: 'Sunday',
2: 'Monday',
3: 'Tuesday',
4: 'Wednesday',
5: 'Thursday',
6: 'Friday',
7: 'Saturday'
};
// Return
return weekDayValues[day];
};
// Log
s.log(2, '201510091437 becomes: ' + getDay( '201510091437' ) );
s.log(2, '201510121437 becomes: ' + getDay( '201510121437' ) );
Last edited by gabrielp on Mon Oct 12, 2015 6:14 pm, edited 2 times in total.
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: Convert Metadata field (Date) to Weekday
Thanks!
But I got Sunday what ever date I put in the first line..
"201510091437" gets Sunday
"201510121437" gets Sunday
And it's Monday here now.
But I got Sunday what ever date I put in the first line..
"201510091437" gets Sunday
"201510121437" gets Sunday
And it's Monday here now.

Between jobs!
Re: Convert Metadata field (Date) to Weekday
I should have started with regex.cap(1) instead of regex.cap(0). I've updated the script in my original post. Let me know if it that works.lombert wrote:Thanks!
But I got Sunday what ever date I put in the first line..
"201510091437" gets Sunday
"201510121437" gets Sunday
And it's Monday here now.
Edit: put it inside a function so you can just call getDay( '201510091437' )
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: Convert Metadata field (Date) to Weekday
The new one gives me this;
201510121437 becomes: Sunday -> Should be Monday
201510091437 becomes: Thursday -> Should be Friday
But this may be a system thing?
In the script the week starts with Sunday, is that the normal way? In Sweden we have Monday as first day? I mean that in your american system first day is sunday and everything works, but I need to change to Monday -> Sunday?
201510121437 becomes: Sunday -> Should be Monday
201510091437 becomes: Thursday -> Should be Friday
But this may be a system thing?
In the script the week starts with Sunday, is that the normal way? In Sweden we have Monday as first day? I mean that in your american system first day is sunday and everything works, but I need to change to Monday -> Sunday?
Between jobs!
Re: Convert Metadata field (Date) to Weekday
I'm a realy noob then it came to script.. 
If I change the settings to start with monday it is working correct.
But how can I now use this in my flow?
The metadata (XML) is "[Metadata.Text:Path="/order/deadline",Dataset="Xml",Model="XML"]" and I want it to be set as an variabel in "Set hierarch path" so I can set a folder with the correct weekday then the files arrives.

If I change the settings to start with monday it is working correct.
But how can I now use this in my flow?
The metadata (XML) is "[Metadata.Text:Path="/order/deadline",Dataset="Xml",Model="XML"]" and I want it to be set as an variabel in "Set hierarch path" so I can set a folder with the correct weekday then the files arrives.
Between jobs!
Re: Convert Metadata field (Date) to Weekday
Ok... clone this repo (or just download the .sscript file): https://github.com/dominickp/SwitchParseDayOfWeeklombert wrote:But how can I now use this in my flow?
The metadata (XML) is "[Metadata.Text:Path="/order/deadline",Dataset="Xml",Model="XML"]" and I want it to be set as an variabel in "Set hierarch path" so I can set a folder with the correct weekday then the files arrives.
Drop in a new scripting configurator and browse for that script. Then, for the "Date String" attribute, choose "Define single-line text with variables". Metadata > Text > "Path >" > Build location path, and select your element that is the timestamp. This should probably be [Metadata.Text:Path="/order/deadline",Dataset="Xml",Model="XML"].
For the "Private Data Key" property, set that to anything you want. Let's call it "LombertsPDKey".
Just pass your job through that script and then in your archive hierarchy, you can now use [Job.PrivateData:Key="LombertsPDKey"] (found in Job > PrivateData within 'Define single-line text with variables') which will be the day that was parsed by the script: Thursday, for example. So just drop that in somewhere where defining your hierarchy path.
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: Convert Metadata field (Date) to Weekday
Big Thanks!
Could I send you a cake I would!
I think I can get this to work now.
Could I send you a cake I would!

I think I can get this to work now.
Between jobs!
Re: Convert Metadata field (Date) to Weekday
Have a new question about the same metadata field.
I have tried to check if the date is "yesterday/older" or "tomorrow/younger" in a "Defining a condition with variables", but if I set the metadata to be a "date" it will not respond.
In the manual it says the string has to be "yyyy-MM-dd.. ..", but I can't change the metadata, it came "yyyyMMdd.. .."..
An ISO 8601 formatted date/time (equivalent to format string "yyyy-MM-ddThh:mm:ss.zzz") or any portion thereof
Enter a format string in the Format argument of the variable to specify which portion of the date and/or time should take part in the comparison
For example, you may enter "yyyy-MM" for the format string and "2007-08" as the comparison value to compare year and month
Why can't Switch recognise that as an date?
I have tried to check if the date is "yesterday/older" or "tomorrow/younger" in a "Defining a condition with variables", but if I set the metadata to be a "date" it will not respond.
In the manual it says the string has to be "yyyy-MM-dd.. ..", but I can't change the metadata, it came "yyyyMMdd.. .."..
An ISO 8601 formatted date/time (equivalent to format string "yyyy-MM-ddThh:mm:ss.zzz") or any portion thereof
Enter a format string in the Format argument of the variable to specify which portion of the date and/or time should take part in the comparison
For example, you may enter "yyyy-MM" for the format string and "2007-08" as the comparison value to compare year and month
Why can't Switch recognise that as an date?
Between jobs!