Time limit on Editing Custom Module Items

I know this is quite a tricky request but I have a Custom Module that needs to be able to be edited from within a secure zone but only up until a certain start date.

That particular start date would be a custom field within the Custom Module. So for example if the event start date is 28th October, we only want people to be able to edit that event data up until the day before but after that it can’t be edited any more.

Any ideas if this could be done?

Hi @SiroccoDigital

Should just be a matter of comparing today’s datetime to your custom field datetime (minus 24 hrs or 86400 seconds to establish a cut-off date).

There’s probably a few ways to do this, but I’d just start by getting both of these dates as seconds (since 1970) using the date: "%s" filter.

So to do this:

{% assign nowDate = "now" | date: "%s" %}  <!-- Today's date, in seconds -->
{% assign cutoffDate = this.startDate | date: "%s" | minus: 86400 %} <!-- Start date minus 24hrs, in seconds -->

The this.startDate above is the reference to your custom start date field, adjust as needed.
This is assuming you have this code on the item detail layout.

Then just compare if the cut-off date is greater or equal to the current date:

{% if cutoffDate >= nowDate %}
<!-- show edit form -->
{% else %}
<!-- show can no longer edit message, etc. -->
{% endif %}

That should do the trick :thinking: :slight_smile:

For reference, Docs on date filters here: https://docs.treepl.co/liquid/liquid-filters#secConvertDate

Wow that looks quite doable @Adam.Wilson. Thank you so much and I will let you know how I go with the implementation.