Question

Extracting hours after day in a string using connector

  • 27 January 2022
  • 2 replies
  • 16 views

I have data for hours coming in this format

 

{Sun|07:00-13:00}{Tue|07:00-13:00}{Wed|07:00-13:00}{Thu|07:00-13:00}{Fri|07:00-13:00}{Sat|07:00-13:00}

 

I need it in an output that I can map to 7 separate fields (Monday hours, Tuesday hours, etc.)

I can’t just use a separator because not every day is always represented. I need someway to say Find SUN and give me back the next 11 characters and if it doesn’t find SUN, to give back blank or 00:00-00:00


This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

2 replies

Userlevel 7
Badge +14

Hi @Brittany 

I’ll put some JavaScript Code together for you.

Userlevel 7
Badge +14

@Brittany 

Try this JavaScript in a Code step: https://zapier.com/apps/code/help

 

CONFIG

 

CODE

let DaysHours = inputData.DaysHours;
if (DaysHours) {
DaysHours = DaysHours.slice(1).slice(0,-1);
DaysHours = DaysHours.split("}{");
}

let HoursMonday = "";
let HoursTuesday = "";
let HoursWednesday = "";
let HoursThursday = "";
let HoursFriday = "";
let HoursSaturday = "";
let HoursSunday = "";

for (let i = 0; i < DaysHours.length; i++) {
if (DaysHours[i].includes("Mon|")) {
HoursMonday = DaysHours[i].split("|")[1];
}
if (DaysHours[i].includes("Tue|")) {
HoursTuesday = DaysHours[i].split("|")[1];
}
if (DaysHours[i].includes("Wed|")) {
HoursWednesday = DaysHours[i].split("|")[1];
}
if (DaysHours[i].includes("Thu|")) {
HoursThursday = DaysHours[i].split("|")[1];
}
if (DaysHours[i].includes("Fri|")) {
HoursFriday = DaysHours[i].split("|")[1];
}
if (DaysHours[i].includes("Sat|")) {
HoursSaturday = DaysHours[i].split("|")[1];
}
if (DaysHours[i].includes("Sun|")) {
HoursSunday = DaysHours[i].split("|")[1];
}
}

output = [{HoursMonday, HoursTuesday, HoursWednesday, HoursThursday, HoursFriday, HoursSaturday, HoursSunday, DaysHours}];

RESULTS