0

I'm stuck in the following problem:

I created a form to the user specify their tasks and say if it will repeat in the future or not.

So, here's an example: I'm adding a task that I have to do every 30th day of each month,but February got only 28/29. If I add '+1 month' to '30/jan/yyyy', it will become '03/mar/yyyy'.

In the form, I have the Date Interval (Begin 'taskWhen' and End 'taskEnd' of the task) and the option to repeat that task:

<div class="form-group">
      <label for="taskWhen">Quando? <small class="text-muted">Dead Line inicial</small></label>
      <input type="date" name="taskWhen" id="taskWhen" class="form-control">
      <small class="text-muted">Utilize o menu no lado direito para exibir o calendário</small>
    </div>

    <div>
        <label>Recorrência <small class="text-muted">/ Periodicidade</small></label>
        <table class="table">
            <thead>
                <tr align="center">
                    <td style="width: 25%">Spot (Não repetir)</td>
                    <td style="width: 25%">Diária</td>
                    <td style="width: 25%">Semanal</td>
                    <td style="width: 25%">Mensal</td>
                </tr>
            </thead>
            <tbody>
                <tr align="center">
                    <td>
                        <input type="radio" name="taskPeriodo" class="radio" value="0" checked="checked">
                    </td>
                    <td>
                        <input type="radio" name="taskPeriodo" class="radio" value="1">
                    </td>
                    <td>
                        <input type="radio" name="taskPeriodo" class="radio" value="7">
                    </td>
                    <td>
                        <input type="radio" name="taskPeriodo" class="radio" value="30">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>

    <div class="form-group" style="display: none;" id="taskFinish">
      <label for="taskEnd">Termina em: <small class="text-muted"></small></label>
      <input type="date" name="taskEnd" id="taskEnd" class="form-control">
      <small class="text-muted">Utilize o menu no lado direito para exibir o calendário</small>
    </div>

I've already made it 'daily' and 'weekly', but the logic to add it by months is getting really hard because of the final day of each month.

Thank you!

Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
  • Pseudo example... `if(month = 'february') {setTaskDay(28);}` – ProEvilz Jan 08 '18 at 11:32
  • There is no perfect solution for this. If the day of month is greater than 28, you'll simply have to check each month and reduce it if necessary. It's tedious, but not hard. –  Jan 08 '18 at 11:34
  • Have a look at this older post https://stackoverflow.com/questions/222309/calculate-last-day-of-month-in-javascript#222439 – FixFaier Jan 08 '18 at 11:34

0 Answers0