From 8e89ac180f38a157b38fae3d2acd304797918cef Mon Sep 17 00:00:00 2001 From: dan63047 Date: Wed, 27 Apr 2022 23:25:34 +0300 Subject: [PATCH] title fix + end of countdown fix --- script.js | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/script.js b/script.js index 1b96969..b76832e 100644 --- a/script.js +++ b/script.js @@ -2,7 +2,7 @@ const maxtimestamp = 2147483647; var readable_timer_mode = 0; var msec_display = true; var fullscreen = false; -var other_counters = [ // Title EN, Title RU, Start Unix timestamp, End Unix timestamp, Description EN, Description RU +const other_counters = [ // Title EN, Title RU, Start Unix timestamp, End Unix timestamp, Description EN, Description RU ["UNIX unsinged 32-bit timestamp", "UNIX 32 бита без знака", 0n, 4294967295n, "Developers of some systems have thought that singed 32-bit may not be enough and decided to use unsinged 32-bit.", "Разработчики некоторых систем додумались, что 32 бита со знаком однажды может не хватить и решили использовать 32 бита без знака."], ["FAT filesystems timestamps", "Штампы времени файловой системы FAT", 315532800n, 4354819198n, "Four bytes are assigned to each timestamp: two for the date and two for the time. The year is stored in the last 7 bits in the format of the number of years since the beginning of the Microsoft era. Hence the range - from 1980 to 2107", "На каждую отметку времени отводится четыре байта: два - на дату и два - на время. Год хранится в последних 7 битах в формате количества лет от начала эпохи Microsoft. Отсюда и диапазон - от 1980 до 2107 года"], ["ext4 Inode Timestamps", "Inode Timestamps файловой системы ext4", -2147483648n, 15032385535n, "Four timestamps are recorded in the lower 128 bytes of the inode structure -- inode change time (ctime), access time (atime), data modification time (mtime), and deletion time (dtime). The four fields are 32-bit signed integers that represent seconds since the Unix epoch (1970-01-01 00:00:00 GMT), which means that the fields will overflow in January 2038. If the inode structure size sb->s_inode_size is larger than 128 bytes and the i_inode_extra field is large enough to encompass the respective i_[cma]time_extra field, the ctime, atime, and mtime inode fields are widened to 64 bits. Within this \"extra\" 32-bit field, the lower two bits are used to extend the 32-bit seconds field to be 34 bit wide; the upper 30 bits are used to provide nanosecond timestamp accuracy. Therefore, timestamps should not overflow until May 2446. dtime was not widened.", "В нижних 128 байтах структуры индексного дескриптора записываются четыре метки времени: время изменения индексного дескриптора (ctime), время доступа (atime), время модификации данных (mtime) и время удаления (dtime). Четыре поля представляют собой 32-разрядные целые числа со знаком, представляющие секунды с эпохи Unix (1970-01-01 00:00:00 GMT), что означает, что поля будут переполнены в январе 2038 года. Если размер структуры inode sb->s_inode_size превышает 128 байт, а поле i_inode_extra достаточно велико, чтобы охватить соответствующее поле i_[cma]time_extra, поля ctime, atime и mtime inode расширяются до 64 бит. В этом «дополнительном» 32-битном поле младшие два бита используются для расширения 32-битного поля секунд до 34-бит; верхние 30 бит используются для обеспечения наносекундной точности отметки времени. Поэтому временные метки не должны переполняться до мая 2446 года. Время dtime не расширялось."], @@ -18,6 +18,7 @@ var language_user = window.navigator ? (window.navigator.language || language_user = language_user.substr(0, 2).toLowerCase(); language_site = (language_user == "ru" || language_user == "by" || language_user == "ua") ? "ru" : "en"; var date_to_local = new Intl.DateTimeFormat(language_site, {timeZone: 'UTC', weekday: 'short', year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric', timeZoneName: 'short'}); +var relative_to_local = new Intl.RelativeTimeFormat(language_site, {numeric: 'auto', style: 'long'}); function ReadableTimerSwitcher(){ readable_timer_mode++ if(readable_timer_mode > 2){readable_timer_mode = 0} @@ -68,6 +69,7 @@ function languageSwitcher(lang_code){ break; } date_to_local = new Intl.DateTimeFormat(language_site, {timeZone: 'UTC', weekday: 'short', year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric', timeZoneName: 'short'}); + relative_to_local = new Intl.RelativeTimeFormat(language_site, {numeric: 'auto', style: 'long'}); } languageSwitcher(language_site); function msecDisplaySwitcher(){ @@ -121,24 +123,38 @@ function Cycle() { if (left <= 0) { clearInterval(c); $("#time-left").html("0"); - $("#time-left-msec").html("000") - $("#title").html("С͓̪̩̳͕͍̄ͮͤ̚̚м̦͎͉̝̋̄е̥͕̫̫̱̱͓̞̾р̞̤̰͖̤̟̫͓̏̍͒ͣ͐͂̚ͅт̗̥̲̩̣̯̹̅ͅь̙͍̟̟̮̩̦̹ͩͤ"); + $("#time-left-msec").html(".000") + $("#title_ru").html("С͓̪̩̳͕͍̄ͮͤ̚̚м̦͎͉̝̋̄е̥͕̫̫̱̱͓̞̾р̞̤̰͖̤̟̫͓̏̍͒ͣ͐͂̚ͅт̗̥̲̩̣̯̹̅ͅь̙͍̟̟̮̩̦̹ͩͤ"); + $("#title_en").html("D̴̠͆̉̑͑̏e̴̦͑́ǎ̷̯̟̳͙t̸̡͔̖̞̝͔̅͌̒̎̓͑͊ͅh̶͈̩̰͈̾̾̑̂̌̇̈́ͅ"); + document.title = (language_site == "ru" ? "С͓̪̩̳͕͍̄ͮͤ̚̚м̦͎͉̝̋̄е̥͕̫̫̱̱͓̞̾р̞̤̰͖̤̟̫͓̏̍͒ͣ͐͂̚ͅт̗̥̲̩̣̯̹̅ͅь̙͍̟̟̮̩̦̹ͩͤ" : "D̴̠͆̉̑͑̏e̴̦͑́ǎ̷̯̟̳͙t̸̡͔̖̞̝͔̅͌̒̎̓͑͊ͅh̶͈̩̰͈̾̾̑̂̌̇̈́ͅ"); + return; + } + var tsec = Math.floor(left % 60), + tmin = Math.floor(left / 60) % 60, + thour = Math.floor(left / 60 / 60) % 24, + tday = Math.floor(left / 60 / 60 / 24) % 365, + ttday = Math.floor(left / 60 / 60 / 24), + ttmonth = Math.floor(left/ 60 / 60 / 24 / 30), + tyear = Math.floor(left / 60 / 60 / 24 / 365); + if (tyear > 0){ + document.title = (language_site == "ru" ? "Проблема 2038 года " : "Problem 2038 ") + relative_to_local.format(tyear, "year") + }else if(ttmonth > 0){ + document.title = (language_site == "ru" ? "Проблема 2038 года " : "Problem 2038 ") + relative_to_local.format(ttmonth, "month") + }else if(ttday > 0){ + document.title = (language_site == "ru" ? "Проблема 2038 года " : "Problem 2038 ") + relative_to_local.format(ttday, "day") + }else if(thour > 0){ + document.title = (language_site == "ru" ? "Проблема 2038 года " : "Problem 2038 ") + relative_to_local.format(thour, "hour") + }else if(tmin > 0){ + document.title = (language_site == "ru" ? "Проблема 2038 года " : "Problem 2038 ") + relative_to_local.format(tmin, "minute") + }else{ + document.title = (language_site == "ru" ? "Проблема 2038 года " : "Problem 2038 ") + relative_to_local.format(tsec, "second") } switch (readable_timer_mode){ case 0: - var tsec = Math.floor(left % 60), - tmin = Math.floor(left / 60) % 60, - thour = Math.floor(left / 60 / 60) % 24, - tday = Math.floor(left / 60 / 60 / 24); - $("#time-left-readable").html("(" + tday + ":" + ("0" + thour).slice(-2) + ":" + ("0" + tmin).slice(-2) + ":" + ("0" + tsec).slice(-2) + ")"); + $("#time-left-readable").html("(" + ttday + ":" + ("0" + thour).slice(-2) + ":" + ("0" + tmin).slice(-2) + ":" + ("0" + tsec).slice(-2) + ")"); break; case 1: - var tsec = Math.floor(left % 60), - tmin = Math.floor(left / 60) % 60, - thour = Math.floor(left / 60 / 60) % 24, - tday = Math.floor(left / 60 / 60 / 24) % 365, - tyear = Math.floor(left / 60 / 60 / 24 / 365); - $("#time-left-readable").html("(" + tyear.toLocaleString(language_site, {style: "unit", unit: "year"}) + " " + tday.toLocaleString(language_site, {style: "unit", unit: "day"}) + " " + ("0" + thour).slice(-2) + ":" + ("0" + tmin).slice(-2) + ":" + ("0" + tsec).slice(-2) + ")"); + $("#time-left-readable").html("(" + tyear.toLocaleString(language_site, {style: "unit", unit: "year", unitDisplay: 'long'}) + " " + tday.toLocaleString(language_site, {style: "unit", unit: "day", unitDisplay: 'long'}) + " " + ("0" + thour).slice(-2) + ":" + ("0" + tmin).slice(-2) + ":" + ("0" + tsec).slice(-2) + ")"); break; case 2: $("#time-left-readable").html(Math.trunc(timestamp).toLocaleString(language_site)+" / "+maxtimestamp.toLocaleString(language_site)+" ("+(timestamp/maxtimestamp).toLocaleString(language_site, {style: "percent", minimumFractionDigits: 8})+")");