How to show an alert with 10 minutes left of a specific time

0

I currently have the following code:

let start_date = '';
        var now = new Date();
        let validation_date = '';
        const $topleft = $(this.refs.topleft);

        const message_popup = result.map(item => {
            if (moment(item.start).format(Config.DateFormat) == moment(now).format(Config.DateFormat))
            {
                start_date = moment(item.start).format(Config.DateTimeFormat);
                validation_date = new Date(moment(start_date).get('year'), moment(start_date).get('month'), moment(start_date).get('date'), moment(start_date).get('hour'), moment(start_date).get('minute'), moment(start_date).get('second'), moment(start_date).get('millisecond')) - now;
                if (validation_date < 0) {
                    //validation_date += 86400000;
                    validation_date += 72000000;
                }
                setTimeout(function ()
                {
                    bootbox.alert({
                        message: '${ILocale.MsgAlertaEventoP1} ${item.title}${ILocale.MsgAlertaEventoP2} ${moment(item.start).format(Config.TimeFormatAmPm)}',
                        className: 'bb-alternate-modal'
                    });
                }, validation_date);
            }
        });

What you want to do is, deploy an alert 10 minutes before the requested time of the BD, some idea of how to do it ... ???

    
asked by Broodwing009 02.10.2017 в 21:58
source

1 answer

0
  

What you want to do is, deploy an alert 10 minutes before the requested time of the BD. Any idea how to do it?

What you should do is first subtract 10 minutes from the date obtained. You finally get the difference in milliseconds between this date and the date of now .

Example

// simula una fecha 1 minuto adelante
const datedb = moment().add(1, 'minutes');
// le restamos 50 segundos (en tu caso es 10 minutos)
const custom = datedb.clone().subtract(50, 'seconds');
// diferencia en ms
const diff = custom - moment();

setTimeout(() => {
  alert('Mensaje');
}, diff);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment-with-locales.min.js"></script>

I recommend working with controlled components as much as possible so that React is responsible for showing the popups and not the DOM directly.

    
answered by 05.10.2017 / 16:35
source