javascript methods for sequence to readable date

c# like java for PI5

Helper 2025-02-19 more updates for Compare
This commit is contained in:
2025-03-26 17:02:35 -07:00
parent 0621d0f07e
commit 919279a917
12 changed files with 1119 additions and 738 deletions

View File

@ -1,4 +1,5 @@
"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);
@ -16,42 +17,7 @@
// 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);
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";
let seconds = time.valueOf() + timezoneOffset;
let epoch = seconds * 10000;
let ticks = epoch + 621355968000000000;
let dateText = seconds + " - " + ticks + " - " + now.toString();
console.log("dateText: " + dateText);
console.log("end");
let original = "d:\\5-Other-Small\\Kanban\\Year-Season\\2025\\2025-0.Winter\\1737913505637";
let segments = original.split('\\');
let path = segments.slice(0, -3).join('\\') + '\\2021\\2021-0.Summer\\123';
console.log(path);
// epoch: 25201000
// ticks: 638665132483790000
// dateText: 638665132483790000 - Wed Nov 06 2024 10:55:58 GMT-0700 (Mountain Standard Time)
@ -59,3 +25,82 @@ console.log(path);
// 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");