<!doctype html>
<html lang="en">

<head>
    <meta charset="utf8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap demo</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.2/font/bootstrap-icons.css">
</head>

<body>
    <style>
        .googleMeatButton {
            width: 100%;
            background-image: linear-gradient(45deg, rgba(32, 191, 85, 1) 0%, rgba(1, 186, 239, 1) 100%);
            border-width: 1px;
            border-color: rgba(2, 73, 71, 1);
            border-radius: 32px;
            padding: 8px;
            text-align: center;
            color: #fff;
            cursor: pointer;
            font-size: 24px;
            font-weight: 700;

        }

        .googleMeatButton:hover {
            background: rgba(80, 227, 194, 1);
        }
    </style>
    <div class="container py-5">
        <button class="googleMeatButton" id="googleMeetLink"><i class="bi bi-bell-fill me-2"></i>Add to Calendar</button>
    </div>
</body>

<script>
    //takes day name and time array [HH,ii,ss]
    // function nextDateTime(day, time) {

    //     let days = {
    //         sunday: 0,
    //         monday: 1,
    //         tuesday: 2,
    //         wednesday: 3,
    //         thursday: 4,
    //         friday: 5,
    //         saturday: 6
    //     };
    //     dayIndex = days[day.toLowerCase()];
    //     var today = new Date();

    //     today.setDate(today.getDate() + (dayIndex - 1 - today.getDay() + 7) % 7 + 1);
    //     today.setHours(time[0] - 5);
    //     today.setMinutes(time[1] - 30);
    //     today.setSeconds(time[2]);

    //     let year = String(today.getFullYear()).padStart(2, 0);
    //     let month = String(today.getMonth() + 1).padStart(2, 0);
    //     let date = String(today.getDate()).padStart(2, 0);
    //     let hour = String(today.getHours()).padStart(2, 0);
    //     let minute = String(today.getMinutes()).padStart(2, 0);
    //     let second = String(today.getSeconds()).padStart(2, 0);
    //     return (year + month + date + 'T' + hour + minute + second + 'Z');
    // }

    // document.getElementById("googleMeetLink").addEventListener("click", function() {

    //     let message = 'Hello sir what are you doing';
    //     let title = 'Learn-PHP-Development-By-Iqbal';
    //     let dayName = 'Saturday';
    //     // [HH,ii,ss]
    //     let startTime = [20, 00, 00];
    //     let endTime = [21, 00, 00];
    //     // YmdTHisZ
    //     let startDate = nextDateTime(dayName, startTime);
    //     let endDate = nextDateTime(dayName, endTime);

    //     window.open('https://calendar.google.com/calendar/u/0/r/eventedit?dates=' + startDate + '/' + endDate + '&details=%3Ca+href%3D%22www.jobaaj.com%22%3E' + message + '%3C/a%3E&text=' + title + '&pli=1', '_blank');

    // });


    //takes date and time array [HH,ii,ss]
    function nextDateTime(day, time) {

        var today = new Date(day);

        today.setHours(time[0] - 5);
        today.setMinutes(time[1] - 30);
        today.setSeconds(time[2]);

        let year = String(today.getFullYear()).padStart(2, 0);
        let month = String(today.getMonth() + 1).padStart(2, 0);
        let date = String(today.getDate()).padStart(2, 0);
        let hour = String(today.getHours()).padStart(2, 0);
        let minute = String(today.getMinutes()).padStart(2, 0);
        let second = String(today.getSeconds()).padStart(2, 0);
        return (year + month + date + 'T' + hour + minute + second + 'Z');
    }

    document.getElementById("googleMeetLink").addEventListener("click", function() {

        let message = 'Hey,<br><br>You will receive all the updates of this event in your private whatsapp group <br><br> Join Now (if you haven\'t joined yet):- <a href="https://2udk.short.gy/data-en-free">Click Here </a> ';
        let title = 'Learn Data Science Analytics by Rakshit Vig';
        let dayDate = '2023-01-02';
        // [HH,ii,ss]
        let startTime = [17, 30, 00];
        let endTime = [21, 00, 00];
        // YmdTHisZ
        let startDate = nextDateTime(dayDate, startTime);
        let endDate = nextDateTime(dayDate, endTime);

        window.open('https://calendar.google.com/calendar/u/0/r/eventedit?dates=' + startDate + '/' + endDate + '&details=' + message + '&text=' + title + '&pli=1', '_blank');

    });
</script>

</html>



<?php

// function nextDateTime($day, $time)
// {
//     $day = strtolower($day);
//     $time[0] = $time[0] - 5;
//     $time[1] = $time[1] - 30;
//     $date = date("Ymd-His", strtotime("next $day, +$time[0] hours, +$time[1] minutes, +$time[0] seconds"));
//     $date = str_replace("-", "T", $date) . "Z";
//     return $date;
// }


// $message = 'Hello sir what are you doing';
// $title = 'Learn-PHP-Development-By-Iqbal';
// $dayName = 'Saturday';
// // [HH,ii,ss]
// $startTime = [20, 00, 00];
// $endTime = [21, 00, 00];
// // YmdTHisZ
// $startDate = nextDateTime($dayName, $startTime);
// $endDate = nextDateTime($dayName, $endTime);

// $link = 'https://calendar.google.com/calendar/u/0/r/eventedit?dates=' . $startDate . '/' . $endDate . '&details=' . $message . '&text=' . $title . '&pli=1';

// echo $link;

?>