How to calculate if my business is open using open hours entity.

0
I am trying to figure out how to display different options based on whether my business is open or closed. I have not been able to crack this nut. I have looked around extensively before asking and I am completely out of ideas.   I created a table with day, open, close where… day = sun. mon. tues, … open = 00 AM, 01 AM, 02 AM,… 12PM, 01 PM, 02 PM,… using an hours enum. closed = same thing as open. I can adjust this table and data as needed of course.   I am trying to use the no/low code methods that exist within Mendix. Partly because I am stubborn, and partly because I want to learn Mendix. This should help me with a deeper understanding.   If you can help, it would be greatly appreciated.   Cheers!!
asked
4 answers
4

You need the formatDateTime function. In a microflow:

  • store the open/closing time as a 24 hour integer 
  • create a variable “Day” using an expression:
formatDateTime([%CurrentDateTime%],'EEE')
  • create a variable “CurrentHour” using an expression:
formatDateTime([%CurrentDateTime%],'HH')
  • Use a retrieve activity to get the first object with xpath like:
[day = $Day]
[open < $CurrentHour and closed > $CurrentHour]


If you get an object, the business is open. If not, the business is closed.

 

 

answered
7

Hi Steven Preston

Instead of using enum create a entity with attributes day(String), from(DateTime), to(DateTime), create a over view pages for this entity. in add/edit page use date and time picker which is available in market place, don’t consider a date just select the time in that.

https://marketplace.mendix.com/link/component/116978

in your view page you can show only time.

 

for visibility there is a default option make use of it.

 

Thanks.

answered
0

Thanks for your fast and expert reply!

 

I had to do some work to get to this point (ie. create the form to add the hours).

 

After some iterations, I ended up dropping the enums for day and open/close.

Created a AreOpen variable as false,

Created a loop to iterate through the list and set the AreOpen variable to true. (I am sure there is a better way, was looking for a object.length equivalent. If there is something like this short of Java, please let me know.) I have not tested this yet.

My next question is-

How do I conditionally show an element on a page?

I have a container with a layout grid inside. From there, content. I want to show this conditionally based upon a variable or other simple mechanism. (I was looking for a object.visible=visible equivalent.)

Essentially what I am trying to do is expose the call option during business hours only.

 

Cheers!!

answered
0

@Javith Baig

Many Thanks!

 

I did something similar but switched to the data grid to populate the table.

 

You did clear something up for me. I could not stich together in my mind how the date/time would really work in my scenario. The documentation states that it always stores a date/time even if the widget (I wanted to say object) is set to show time. I was not totally clear on that. While I did use the date/time widget for some tests, I was not feeling too confident that a time would actually be saved that would be easily reused. My mind goes immediately to simple. I have learned a valuable lesson here. I am grateful.

 

Mendix is really something. – Huh? I like it.

 

Cheers!!

answered