Adjusting and interacting with time can be tricky across timezones, date formats, and desired date formats. Tulip enables apps to conform to your existing standards, and understanding how to work with time should be in the toolkit of every app builder.
How this App Works
This single step app shows most of the most common date manipulations you might need in your Tulip solution.
Built in Timers
There are some timers automatically built into your app. These timers can be referenced in triggers, stored to tables, and more
Time spent in app is the elapsed time since the app was last restarted, or the last completion happened. More information on completions here. This value might be useful for tracking the average time needed to complete an assembly or training process.
Time spent on step tracks the elapsed time a user has spent on a specific step. This data could be tracked to understand what part of your process is taking most of your operator time.
Current time tracks the current time, this time can be used to adjust trigger logic for different shifts, track when activities have happened, and more.
The simple timer shows how you can create your own timers. This technique can be useful to extend the capabilities of the built in timers. For example, if you want to track the time for users to get through a specific set of steps, not a single step or whole app.
All of the logic for this timer exists under each button's respective triggers. Check out this article for more information about triggers.
The START button sets the current time to a start time variable if it is currently blank.
The STOP button sets the current time to the End time variable, and does the math to calculate the elapsed time between the start and stop time. This is the first time you are seeing an expression in a trigger. Expressions extend the capabilities of triggers. More information about expressions is available here.
The RESET button clears the Start time, End time, and Duration variables.
Timer Based Triggers
Running logic on a periodic basis further extends the ways a Tulip app can be used. Timer based triggers run every X seconds, and can execute any trigger logic.
Timer based triggers run on the step level. This means you will need to select the STEP tab on the configuration slide-out to create/view/edit timer triggers.
In this case, the timer triggers are just adding 1 to an existing variables value.
Transforming Time Triggers
Reformatting how time is displayed, adding two times together, and converting text to datetime variables are all key techniques to working with datetimes in Tulip.
Adding time together is simple and quite powerful. Many you want to calculate the order due date based on the current time and lead-time, or you want to calculate when an audit needs to happen based on when it happened last.
Datetimes can only have other datetimes or intervals added or subtracted from, so in this trigger we will need to convert the number the user enters into an interval before adding it to the current time. We do this conversion with the SECONDS_TO_INTERVAL function. This function takes a number input and converts it to an interval. We need to convert the time in days that the user enters into seconds, we do this by 60*60*24. This interval is added to the current time and stored to a variable.
Rounding dates allows you to round the current time to whatever interval matters to you. Maybe you want to calculate how much time has elapsed in a shift, using the ROUNDDATETIME will allow you to round down the current time to get the beginning of the day.
The trigger below takes the current time, and rounds it down to the nearest day. 'day' in this expression can be replaced with the desired time period. More information about this function is available here.
Converting text to datetimes is very powerful when working with existing systems that have their own date format that is transferred to Tulip as raw text.
The TEXTTODATETIME function takes in text and the format of that date will take and converts the input text to a datetime object. When passing '2022-03-01' to this function, we use the 'YYYY-MM-DD' to tell the TEXTTODATETIME function the month is 03 and the day is 01, not the opposite. This document goes into more detail about different date formats.