"use strict";

// DateTime normal = DateTime.Now.ToUniversalTime();
// logger.LogInformation("Now - ToUniversalTime: {ticks}", normal.Ticks);
// DateTime utc1970DateTime = new(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
// logger.LogInformation("utc1970DateTime: {ticks}", utc1970DateTime.Ticks);
// logger.LogInformation("Subtract: {ticks}", DateTime.Now.Subtract(utc1970DateTime).Ticks);
// var epoch = new Date('1970-01-01T00:00:01');
// console.log("epoch: " + epoch.valueOf());
// var date = new Date();
// var timezoneOffset = date.getTimezoneOffset();
// console.log("timezoneOffset: " + timezoneOffset);
// var secondsAfter = (date.getTime().valueOf() + timezoneOffset) * 10000;
// var ticks = secondsAfter + 621355968000000000;
// console.log("ticks: " + ticks);
// var dateText = ticks + " - " + date.toString();
// console.log("dateText: " + dateText);
// DateTime utcMeDateTime = new(1980, 1, 17, 0, 0, 0, DateTimeKind.Utc);
// long meTotalSeconds = (long)Math.Floor(fileInfo.LastWriteTime.ToUniversalTime().Subtract(utcMeDateTime).TotalSeconds);

// epoch:                     25201000
// ticks:           638665132483790000
// dateText:        638665132483790000 - Wed Nov 06 2024 10:55:58 GMT-0700 (Mountain Standard Time)
// Now - To:        638665132334594771
//                  638665135325760000
//                  638665136814890000
// utc1970DateTime: 621355968000000000

function getDateText() {
    let result;
    const now = new Date();
    const time = now.getTime();
    const year = now.getFullYear();
    const start = new Date(year, 0, 0);
    const oneDay = 1000 * 60 * 60 * 24;
    const timezoneOffset = now.getTimezoneOffset();
    const diff = (now - start) + ((start.getTimezoneOffset() - timezoneOffset) * 60 * 1000);
    const day = Math.floor(diff / oneDay);
    console.log('Day of year: ' + day);
    var season = year + "-";
    if (day < 78)
        season = season + "0.Winter";
    else if (day < 124)
        season = season + "1.Spring";
    else if (day < 171)
        season = season + "2.Spring";
    else if (day < 217)
        season = season + "3.Summer";
    else if (day < 264)
        season = season + "4.Summer";
    else if (day < 309)
        season = season + "5.Fall";
    else if (day < 354)
        season = season + "6.Fall";
    else
        season = season + "7.Winter";
    const seconds = time.valueOf() + timezoneOffset;
    const epoch = seconds * 10000;
    const ticks = epoch + 621355968000000000;
    result = seconds + " - " + ticks + " - " + now.toString();
    return result;
}

const dateText = getDateText();
console.log("dateText: " + dateText);

function getPath() {
    let result;
    const original = "d:\\5-Other-Small\\Kanban\\Year-Season\\2025\\2025-0.Winter\\1737913505637";
    const segments = original.split('\\');
    result = segments.slice(0, -3).join('\\') + '\\2021\\2021-0.Summer\\123';
    return result;
}

const path = getPath();
console.log("path: " + path);

// https://tickstodatetime.wassupy.com/?ticks=638784250251441727

function getInfinityQS(value, sequence) {
    let result;
    if (sequence.length < 18)
        result = [value];
    else {
        const now = new Date();
        const epochHour = 36000000000;
        const epochTicks = 621355968000000000;
        const timezoneHourOffset = now.getTimezoneOffset() / 60;
        const timezoneOffset = timezoneHourOffset * epochHour;
        const milliseconds = (sequence - epochTicks + timezoneOffset) / 10000;
        const flooredMilliseconds = Math.floor(milliseconds / (60 * 1000)) * (60 * 1000);
        const ceiledMilliseconds = Math.ceil(milliseconds / (60 * 1000)) * (60 * 1000);
        result = [(flooredMilliseconds / 1000), (ceiledMilliseconds / 1000)];
    }
    return result;
}

const date = '3/26/2025';
const infinityQS = 1742853453;
const sequence = '638784250251441727';
const values = getInfinityQS(date, sequence);
console.info("InfinityQS: " + values);
if (values[0] < infinityQS && values[1] > infinityQS)
    console.info("InfinityQS: Pass");
else
    console.warn("InfinityQS: Fail");