Name: Check-In Countdown
Tag Name: checkincountdown
Tag Type: Inline

Description:
====================================
Calculates how much time is left until the check-in window starts for a specific schedule or the schedule for a specific group.


Documentation:
====================================
<p><strong>Usage:</strong></p>
<pre>{[ checkincountdown groupid:'1234' ]}</pre>
<p>&nbsp; &nbsp; - or -</p>
<pre>{[ checkincountdown scheduleid:'123' ]}</pre>
<p><strong>Returns:</strong></p>
<p>If the next check-in is on a future date:</p>
<pre>up to xx minutes before the event on DayOfTheWeek</pre>
<p>If the next check-in is later on the current date:</p>
<pre>in xx hours, yy minutes</pre>
<p>If the next check-in starts within 60 seconds:</p>
<pre>soon</pre>
<p>If check-in has already closed:</p>
<pre>closed</pre>
<p>Otherwise, nothing is returned.</p>


Shortcode Markup:
====================================
{%- if groupid != empty -%}
    {%- assign group = groupid | GroupById -%}
    {%- assign groupSchedule = group.Schedule -%}
{%- elseif scheduleid != empty -%}
    {%- schedule id:'{{ scheduleid }}' -%}
        {%- assign groupSchedule = schedule -%}
    {%- endschedule -%}
{%- endif -%}
{%- assign openOffset = groupSchedule.CheckInStartOffsetMinutes | Times:-1 | AsString | Default:'-30' | AsInteger -%}
{%- assign now = 'Now' | Date:'M/dd/yyyy h:mm:ss tt' | AsDateTime -%}
{%- if groupSchedule.iCalendarContent != empty -%}
    {%- assign nextStartDateTime =  groupSchedule.iCalendarContent | DatesFromICal:1,'startdatetime' | Index:0 %}
{%- endif -%}
{%- if nextStartDateTime -%}
    {%- assign openDateTime = nextStartDateTime | DateAdd:openOffset,'m' | AsDateTime -%}
{%- elseif groupSchedule.WeeklyDayOfWeek -%}
    {%- assign dayOfWeek = now | Date:'dddd' -%}
    {%- assign startDate = now -%}
    {%- assign groupDayOfWeek = groupSchedule.WeeklyDayOfWeek | AsString -%}
    {%- if dayOfWeek != groupDayOfWeek -%}
        {%- assign startDate = startDate | NextDayOfTheWeek:groupDayOfWeek -%}
    {%- endif -%}
    {%- if groupSchedule.WeeklyTimeOfDay -%}
        {%- assign startDateTime = startDate | Date:'M/dd/yyyy' | Append:' ' | Append:groupSchedule.WeeklyTimeOfDay | Date:'M/dd/yyyy h:mm:ss tt' -%}
    {%- else -%}
        {%- assign startDateTime = startDate | Date:'M/dd/yyyy 00:00:00' -%}
    {%- endif -%}
    {%- assign openDateTime = startDateTime | DateAdd:openOffset,'m' | AsDateTime -%}
{%- endif -%}
{%- if openDateTime -%}
    {%- assign seconds = now | DateDiff:openDateTime,'s' -%}
    {%- assign minutes = seconds | DividedBy:60,2 | Ceiling -%} 
    {%- if minutes > 1440 -%}
        up to {{ openOffset | Times:-1 | }} minutes before the event on {{ openDateTime | Date:'dddd' }}
    {%- elseif minutes > 60 -%}
        {%- assign hours = minutes | DividedBy:60,2 | Floor -%}
        {%- assign minutes = minutes | Modulo:60 -%}
        in {{ hours }} {{ 'hour' | PluralizeForQuantity:hours }}, {{ minutes }} {{ 'minute' | PluralizeForQuantity:minutes -}}
    {%- elseif minutes > 0 -%}
        in {{ minutes }} {{ 'minute' | PluralizeForQuantity:minutes -}}
    {%- elseif minutes == 0 -%}
        soon
    {%- else -%}
        {%- assign minutes = minutes | Times:-1 -%}
        {%- assign closeOffset = groupSchedule.CheckInEndOffsetMinutes | AsString | Default:'30' | AsInteger -%}
        {%- assign duration = openOffset | Times: -1 | Plus:closeOffset -%}
        {%- if minutes > duration -%}closed{%- endif -%}
    {%- endif -%}
{%- else -%}
    closed
{%- endif -%}


Parameters:
====================================
groupid (empty value)
scheduleid (empty value)


Enabled Lava Commands: 
====================================
RockEntity