Skip to content

Commit

Permalink
馃悰 (setVariable) Fix timeZone variable parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Feb 16, 2024
1 parent 3e0d3e7 commit 519f3aa
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions packages/bot-engine/blocks/logic/setVariable/executeSetVariable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,31 @@ const getExpressionToEvaluate =
const phoneNumber = state.whatsApp?.contact.phoneNumber
return phoneNumber ? `"${state.whatsApp?.contact.phoneNumber}"` : null
}
case 'Now':
if (isEmpty(options.timeZone)) return 'new Date().toISOString()'
return toISOWithTz(new Date(), options.timeZone)
case 'Now': {
const timeZone = parseVariables(
state.typebotsQueue[0].typebot.variables
)(options.timeZone)
if (isEmpty(timeZone)) return 'new Date().toISOString()'
return toISOWithTz(new Date(), timeZone)
}

case 'Today':
return 'new Date().toISOString()'
case 'Tomorrow': {
if (isEmpty(options.timeZone))
const timeZone = parseVariables(
state.typebotsQueue[0].typebot.variables
)(options.timeZone)
if (isEmpty(timeZone))
return 'new Date(Date.now() + 86400000).toISOString()'
return toISOWithTz(new Date(Date.now() + 86400000), options.timeZone)
return toISOWithTz(new Date(Date.now() + 86400000), timeZone)
}
case 'Yesterday': {
if (isEmpty(options.timeZone))
const timeZone = parseVariables(
state.typebotsQueue[0].typebot.variables
)(options.timeZone)
if (isEmpty(timeZone))
return 'new Date(Date.now() - 86400000).toISOString()'
return toISOWithTz(new Date(Date.now() - 86400000), options.timeZone)
return toISOWithTz(new Date(Date.now() - 86400000), timeZone)
}
case 'Random ID': {
return `"${createId()}"`
Expand Down

0 comments on commit 519f3aa

Please sign in to comment.