Expand my Community achievements bar.

Check-in Date (eVar42) Classification by Classification Importer

Avatar

Level 2

Check-in Date (eVar42) - This Evar contains values like - "Fri Nov 18 2023"

I would like to have classifications built for this in the following formats

Fiscal Week (Monday – Sunday)

  • Date:                                   MM/DD/YYYY (11/18/2023)
  • Week Number:                 YYYY:FW##  (ex. 2023:FW49)
  • Month:                               YYYY:FM## (ex. 2023:FM11) - Nov
  • Quarter:                             YYYY:FQ## (ex. 2023:FQ04) - Q4
  • Year:                                    YYYY (ex. 2023)

Standard Week (Sunday – Saturday, Regular Month Calendar 1st-31st)

  • Date:                                   MM/DD/YYYY (11/18/2023)
  • Week Number:                 YYYY:SW##  (ex. 2023:SW49)
  • Month:                               YYYY:SM## (ex. 2023:SM01)
  • Quarter:                             YYYY:SQ## (ex. 2023:SQ04)
  • Year:                                    YYYY (ex. 2023)

I want this evar to classify by Date, Month, week, Week number, Year, Quarter. using Classification importer.

 

6 Replies

Avatar

Level 10

This can be done with either the importer or the builder. In either case, someone is going to need to write a lot of parse and transform code (in regex or some other). 

It might make it a bit easier if you can modify the value passed to the evar initially to use week day and month numbers instead of alpha.

So what's the point of all these classifications?

Avatar

Community Advisor

I agree with everything @RobertBlakeley said... Classification or Builder could have some issues...

 

Particularly where you need to figure out the week of the year, there's a lot of logic that would have to be built into this with Regex... the alternative is to provide a 1 to 1 mapping for every possible date (Classification importer) which doesn't seem terribly efficient or scale-able...

 

Also, parsing "text" values, rather than numerical is going to be more challenging...  

 

Passing the dates in a standard ISO format would be more reliable for creating rules around them.... 

 

You may want to consider parsing some of this info in Launch, where you have access to JavaScript and being able to use actual date logic... maybe a mix of that and classifications? 

Hi

Here we are capturing the Check in Date - this is basically the booking website for Hotels. So , Does there is a way to classify using the Classification importer. Please Help

Avatar

Community Advisor

I get that this is a check in date, but you should be able to to use Launch to manipulate the date data better.. basically do some pre-work in Launch to make your life easier in analytics... 

 

Trying to parse date information via regex from a string value is very hard. Even trying to parse a numerical formatted date (still string) via regex is hard. Parsing information from an actual date object using scripting languages is easy.

 

ISO 8601 is an international standard date format. It is much easier to work with than the "human readable" format you have currently.

 

Human Readable: Fri Nov 18 2023

ISO 8601: 2023-11-18

 

(This standard also includes standards for adding timestamps, if you had to go to that granularity, such as 2023-11-18T13:54:36Z-0500 - which represents the time and timezone)

 

Technically, both the human readable and the ISO date can be parsed cast as a date object in JavaScript... but when it comes to Regex, it's a lot harder...

In JS you could easily do the following in Launch:

 

var checkInDate = new Date("Fri Nov 18 2023");
// results in "Fri Nov 17 2023 19:00:00 GMT-0500 (Eastern Standard Time)"

// Date
var date = checkInDate.getMonth()+1 + "/" + checkInDate.getDate() + "/" + checkInDate.getFullYear();
// "11/18/2023"

// Week Number
// Note this is based on Gregorian Calendar, you are using fiscal weeks and would have to adjust it
startDate = new Date(checkInDate.getFullYear(), 0, 1);
var days = Math.floor((checkInDate - startDate) /
    (24 * 60 * 60 * 1000));
var weekNumber = Math.ceil(days / 7);
var weekNumberFinal = checkInDate.getFullYear() + ":FW" + weekNumber;
// results in "2023:FW46"  (looks like you have to adjust by 3 weeks for your fiscal year, you wanted "49", this gets you "46")

// Etc

 

 

 

Whereas, if you are trying to do this all via classifications, you will have to have much more complex rules to read the text version of the month to parse out the right numbers, then you would have to have combination text month and day number logic (for each week) to get the "week number"

 

 

To be honest, if I were doing this, I would actually parse all the values the way you want in Launch, pass them as one big pipe delimited string like so:

"11/18/2023|2023|2023:FW49|2023:FM11|2023:FQ04|2023:SW49|2023:SM01|2023:SQ04"

 

Then use Classifications to just parse out parts by position....something like:

/(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)\|(.*)/g

 

Then just take group1, or group2, or group8, etc into your classification....

Group1 being the Date

Group2 being the Year

Group3 being FW Number

etc

 

Make your life easier by using Launch to do the "heavy lifting", which will be much easier using JS than Regex.

Avatar

Community Advisor

No problem

 

There are often many ways to do things, and while in theory you could use Regex for this, I just feel that the variations you would have to create would be hard to write and harder to maintain...

 

If you aren't a JS coder, you could potentially get help from a developer in your company... or I could help with the rest of the logic (which I really only touched on above). If you are comfortable with code, this should be pretty easy for you, just test and make sure that everything comes out as you expect it...