Anonymous Anonymous - 1 month ago
247 0

No description

TypeScript

quick Dump

getData().then(r => {
    r.data.data.finalTimeline.rotations[0].periods.forEach(r => {
        //Start Date
        let syear: number = +r.startDate.toString().substring(0, 4)
        let smonth: number = (+r.startDate.toString().substring(5, 7)) - 1
        let sday: number = +r.startDate.toString().substring(8, 10)
        let shour: number = +r.startDate.toString().substring(11, 13)
        let smin: number = +r.startDate.toString().substring(15, 16)
        let ssec: number = +r.startDate.toString().substring(18, 19)

        let startDaten: Date
        startDaten = new Date(syear, smonth, sday, shour, smin, ssec)

        //EndDate
        let eyear: number = +r.endDate.toString().substring(0, 4)
        let emonth: number = (+r.endDate.toString().substring(5, 7)) - 1
        let eday: number = +r.endDate.toString().substring(8, 10)
        let ehour: number = +r.endDate.toString().substring(11, 13)
        let emin: number = +r.endDate.toString().substring(15, 16)
        let esec: number = +r.endDate.toString().substring(18, 19)

        let endDate: Date
        endDate = new Date(eyear, emonth, eday, ehour, emin, esec)

debugger
        //get hours& Days
        let total_hour: number
        total_hour = +((endDate.getTime() - startDaten.getTime()) / (1000 * 60 * 60)).toFixed(2)
        let total_days: number
        total_days = +(total_hour / 24).toFixed(2)

        let NationalHoliday: number
        NationalHoliday = 0

        let Weekend: number
        Weekend = 0


        for (let jumpDate = new Date (startDaten); jumpDate <= endDate; jumpDate.setDate(jumpDate.getDate() + 1)) {
            if (jumpDate.getDay() == 0 || 6) {
                Weekend++
            }

            let year: number = +jumpDate.toISOString().toString().substring(0, 4)
            let month: number = +jumpDate.toISOString().toString().substring(5, 7)
            let day: number = +jumpDate.toISOString().toString().substring(8, 10)

            getDate(year, month, day)
                 .then(p => {
                if (p.data.isHoliday == true) {
                    NationalHoliday++
                }
                console.log(NationalHoliday)
            })

        }

        //get all into an Array
        let tempStore :string
        tempStore = `'${startDaten.toDateString()}','${endDate.toDateString()}','${total_hour}','${total_days}','${NationalHoliday}','${Weekend}','${r.recipient.name}'`
        body.push(tempStore)


    })

    console.log(body)
    const csvWriter = createObjectCsvWriter({
        path: '../StoreExe/file.csv',
        header: header
    });



    csvWriter.writeRecords(body)       // returns a promise
        .then(() => {
            console.log('...Done');
        });

}).catch(function (error) {
    console.log(error);
});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download