From 57eade4eae1653001a88d027ab58e3c78e390604 Mon Sep 17 00:00:00 2001 From: SharkPool-SP <139097378+SharkPool-SP@users.noreply.github.com> Date: Tue, 22 Aug 2023 21:48:34 -0700 Subject: [PATCH 01/30] Update time.js --- extensions/-SIPC-/time.js | 218 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 210 insertions(+), 8 deletions(-) diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index 6a8413c821..cd689f4e40 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -1,14 +1,20 @@ -// Name: Time -// ID: sipctime -// Description: Blocks for interacting with unix timestamps and other date strings. -// By: -SIPC- +/* Name: Time +* ID: sipctime +* Old Description: Blocks for interacting with unix timestamps and other date strings. +* Updated Description: Blocks for Time, Date, and Time Zone calculations and interactions. +* Main Extension By: -SIPC- +* Calculation Blocks By: SharkPool +*/ (function (Scratch) { "use strict"; - const icon = + + const menuIconURI = "data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHdpZHRoPSI4MS44ODU0IiBoZWlnaHQ9IjgwLjYwMzA4IiB2aWV3Qm94PSIwLDAsODEuODg1NCw4MC42MDMwOCI+PGcgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTE5OS4wNTczLC0xMzkuNjk4NDYpIj48ZyBkYXRhLXBhcGVyLWRhdGE9InsmcXVvdDtpc1BhaW50aW5nTGF5ZXImcXVvdDs6dHJ1ZX0iIGZpbGwtcnVsZT0ibm9uemVybyIgc3Ryb2tlPSJub25lIiBzdHJva2UtbGluZWNhcD0iYnV0dCIgc3Ryb2tlLWxpbmVqb2luPSJtaXRlciIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBzdHJva2UtZGFzaGFycmF5PSIiIHN0cm9rZS1kYXNob2Zmc2V0PSIwIiBzdHlsZT0ibWl4LWJsZW5kLW1vZGU6IG5vcm1hbCI+PHBhdGggZD0iTTI4MC45NDI3LDE4MGMwLDIyLjI1NzkyIC0xOC4zMzA2Nyw0MC4zMDE1NCAtNDAuOTQyNyw0MC4zMDE1NGMtMjIuNjEyMDMsMCAtNDAuOTQyNywtMTguMDQzNjEgLTQwLjk0MjcsLTQwLjMwMTU0YzAsLTIyLjI1NzkyIDE4LjMzMDY3LC00MC4zMDE1NCA0MC45NDI3LC00MC4zMDE1NGMyMi42MTIwMywwIDQwLjk0MjcsMTguMDQzNjEgNDAuOTQyNyw0MC4zMDE1NHoiIGZpbGw9IiNmZjgwMDAiIHN0cm9rZS13aWR0aD0iMCIvPjxwYXRoIGQ9Ik0yNjYuNTM0MzcsMTgwYzAsMTQuNjQxMjkgLTExLjg5MzA4LDI2LjUzNDM3IC0yNi41MzQzNywyNi41MzQzN2MtMTQuNjQxMjksMCAtMjYuNTM0MzcsLTExLjg5MzA4IC0yNi41MzQzNywtMjYuNTM0MzdjMCwtMTQuNjQxMjkgMTEuODkzMDgsLTI2LjUzNDM3IDI2LjUzNDM3LC0yNi41MzQzN2MxNC42NDEyOSwwIDI2LjUzNDM3LDExLjg5MzA4IDI2LjUzNDM3LDI2LjUzNDM3ek0yNTMuMjE5OCwxODUuOTcwMjNsLTExLjMyNDQ5LC02LjUzODgzdi0xNC41OTM5aC0zLjc5MDYydjE3LjA1NzgxaDAuNTIxMjFsMTIuNjk4NTksNy4zNDQzM3oiIGZpbGw9IiNmZmZmZmYiIHN0cm9rZS13aWR0aD0iMSIvPjwvZz48L2c+PC9zdmc+PCEtLXJvdGF0aW9uQ2VudGVyOjQwLjk0MjY5NjA1MzgwMTE0OjQwLjMwMTUzNTI2NTQ4NjcwNi0tPg=="; - const icon2 = + + const blockIconURI = "data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHdpZHRoPSIxNzUiIGhlaWdodD0iMTc1IiB2aWV3Qm94PSIwLDAsMTc1LDE3NSI+PGcgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTE1Mi41LC05Mi41KSI+PGcgZGF0YS1wYXBlci1kYXRhPSJ7JnF1b3Q7aXNQYWludGluZ0xheWVyJnF1b3Q7OnRydWV9IiBmaWxsPSIjZmZmZmZmIiBmaWxsLXJ1bGU9Im5vbnplcm8iIHN0cm9rZT0ibm9uZSIgc3Ryb2tlLXdpZHRoPSIxIiBzdHJva2UtbGluZWNhcD0iYnV0dCIgc3Ryb2tlLWxpbmVqb2luPSJtaXRlciIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBzdHJva2UtZGFzaGFycmF5PSIiIHN0cm9rZS1kYXNob2Zmc2V0PSIwIiBzdHlsZT0ibWl4LWJsZW5kLW1vZGU6IG5vcm1hbCI+PHBhdGggZD0iTTMyNy41LDE4MGMwLDQ4LjI4MTI1IC0zOS4yMTg3NSw4Ny41IC04Ny41LDg3LjVjLTQ4LjI4MTI1LDAgLTg3LjUsLTM5LjIxODc1IC04Ny41LC04Ny41YzAsLTQ4LjI4MTI1IDM5LjIxODc1LC04Ny41IDg3LjUsLTg3LjVjNDguMjgxMjUsMCA4Ny41LDM5LjIxODc1IDg3LjUsODcuNXpNMjgzLjU5Mzc1LDE5OS42ODc1bC0zNy4zNDM3NSwtMjEuNTYyNXYtNDguMTI1aC0xMi41djU2LjI1aDEuNzE4NzVsNDEuODc1LDI0LjIxODc1eiIvPjwvZz48L2c+PC9zdmc+PCEtLXJvdGF0aW9uQ2VudGVyOjg3LjU6ODcuNS0tPg=="; + class Time { getInfo() { return { @@ -17,9 +23,13 @@ color1: "#ff8000", color2: "#804000", color3: "#804000", - menuIconURI: icon, - blockIconURI: icon2, + menuIconURI, + blockIconURI, blocks: [ + { + blockType: Scratch.BlockType.LABEL, + text: 'Time Conversions', + }, { opcode: "Timestamp", blockType: Scratch.BlockType.REPORTER, @@ -70,12 +80,116 @@ }, }, }, + { + blockType: Scratch.BlockType.LABEL, + text: 'Time Calculations', + }, + { + opcode: 'calculatetimedurationfromdate', + blockType: Scratch.BlockType.REPORTER, + text: 'time duration from [DATE] to current date in [TIME_MENU]', + arguments: { + DATE: { + type: Scratch.ArgumentType.STRING, + defaultValue: '2006-04-16' + }, + TIME_MENU: { + type: Scratch.ArgumentType.STRING, + menu: 'Time', + defaultValue: 'day' + }, + } + }, + { + opcode: 'calculatetimedurationfromtime', + blockType: Scratch.BlockType.REPORTER, + text: 'time duration from [START_HOUR]:[START_MINUTE] to current time in [TIME_MENU]', + arguments: { + START_HOUR: { + type: Scratch.ArgumentType.NUMBER, + defaultValue: 0 + }, + START_MINUTE: { + type: Scratch.ArgumentType.NUMBER, + defaultValue: 0 + }, + TIME_MENU: { + type: Scratch.ArgumentType.STRING, + menu: 'Time', + defaultValue: 'hour' + }, + } + }, + { + opcode: 'calculatetimedifference', + blockType: Scratch.BlockType.REPORTER, + text: 'difference between [START_TIME] and [END_TIME] in [TIME_MENU]', + arguments: { + START_TIME: { + type: Scratch.ArgumentType.STRING, + defaultValue: '00:00' + }, + END_TIME: { + type: Scratch.ArgumentType.STRING, + defaultValue: '00:00' + }, + TIME_MENU: { + type: Scratch.ArgumentType.STRING, + menu: 'Time', + defaultValue: 'hour' + }, + } + }, + { + opcode: 'converttotime', + blockType: Scratch.BlockType.REPORTER, + text: 'convert [VALUE] to time (day:hour:minute)', + arguments: { + VALUE: { + type: Scratch.ArgumentType.NUMBER, + defaultValue: 0 + }, + } + }, + { + opcode: 'daysinmonth', + blockType: Scratch.BlockType.REPORTER, + text: 'number of days in [MONTH] [YEAR]', + arguments: { + MONTH: { + type: Scratch.ArgumentType.STRING, + menu: 'Months', + defaultValue: 'January' + }, + YEAR: { + type: Scratch.ArgumentType.STRING, + defaultValue: '2000' + }, + } + } ], menus: { Time: { acceptReporters: true, items: ["year", "month", "day", "hour", "minute", "second"], }, + Months: { + acceptReporters: true, + items: [ + 'January', + 'February', + 'March', + 'April', + 'May', + 'June', + 'July', + 'August', + 'September', + 'October', + 'November', + 'December' + ] + }, }, }; } @@ -138,6 +252,94 @@ let timestamp = Date.parse(data3); return timestamp; } + + calculateTimeDifference(startDate, endDate, timeMenu) { + const timeDiff = Math.abs(endDate.getTime() - startDate.getTime()); + + switch (timeMenu) { + case 'year': + return Math.floor(timeDiff / (1000 * 60 * 60 * 24 * 365)); + case 'month': + return Math.floor(timeDiff / (1000 * 60 * 60 * 24 * 30)); + case 'day': + return Math.floor(timeDiff / (1000 * 60 * 60 * 24)); + case 'hour': + return Math.floor(timeDiff / (1000 * 60 * 60)); + case 'minute': + return Math.floor(timeDiff / (1000 * 60)); + case 'second': + return Math.floor(timeDiff / 1000); + } + } + + calculatetimedurationfromdate(args) { + const dateString = args.DATE ? args.DATE : null; + const timeMenu = args.TIME_MENU; + const startDate = new Date(dateString); + const endDate = new Date(); + return this.calculateTimeDifference(startDate, endDate, timeMenu); + } + + calculatetimedurationfromtime(args) { + const startHour = args.START_HOUR ? args.START_HOUR : null; + const startMinute = args.START_MINUTE ? args.START_MINUTE : null; + const timeMenu = args.TIME_MENU; + const startDate = new Date(); + startDate.setHours(startHour, startMinute, 0, 0); + const endDate = new Date(); + return this.calculateTimeDifference(startDate, endDate, timeMenu); + } + + calculatetimedifference(args) { + const startTime = args.START_TIME ? args.START_TIME : null; + const endTime = args.END_TIME ? args.END_TIME : null; + const timeMenu = args.TIME_MENU; + const startDate = new Date(); + const endDate = new Date(); + const startHour = parseInt(startTime.split(':')[0]); + const startMinute = parseInt(startTime.split(':')[1]); + const endHour = parseInt(endTime.split(':')[0]); + const endMinute = parseInt(endTime.split(':')[1]); + startDate.setHours(startHour, startMinute, 0, 0); + endDate.setHours(endHour, endMinute, 0, 0); + return this.calculateTimeDifference(startDate, endDate, timeMenu); + } + + converttotime(args) { + const value = args.VALUE ? args.VALUE : 0; + const seconds = Math.floor(value); + const minutes = Math.floor(seconds / 60); + const hours = Math.floor(minutes / 60); + const days = Math.floor(hours / 24); + + const timeString = `${hours % 24}:${minutes % 60}:${seconds % 60}`; + return timeString; + } + + daysinmonth(args) { + const month = args.MONTH; + const year = args.YEAR ? args.YEAR : null; + const date = new Date(year, this._getMonthIndex(month) + 1, 0); + return date.getDate(); + } + + _getMonthIndex(month) { + const months = [ + 'January', + 'February', + 'March', + 'April', + 'May', + 'June', + 'July', + 'August', + 'September', + 'October', + 'November', + 'December' + ]; + return months.indexOf(month); + } } Scratch.extensions.register(new Time()); })(Scratch); From e57e3a654e0d8ae20c63c329a03f747b7cc4a372 Mon Sep 17 00:00:00 2001 From: SharkPool-SP <139097378+SharkPool-SP@users.noreply.github.com> Date: Tue, 22 Aug 2023 21:56:15 -0700 Subject: [PATCH 02/30] Update time.js --- extensions/-SIPC-/time.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index cd689f4e40..4d4d77360a 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -1,10 +1,9 @@ -/* Name: Time -* ID: sipctime -* Old Description: Blocks for interacting with unix timestamps and other date strings. -* Updated Description: Blocks for Time, Date, and Time Zone calculations and interactions. -* Main Extension By: -SIPC- -* Calculation Blocks By: SharkPool -*/ +// Name: Time +// ID: sipctime +// Old Description: Blocks for interacting with unix timestamps and other date strings. +// Updated Description: Blocks for Time, Date, and Time Zone calculations and interactions. +// Main Extension By: -SIPC- +// Calculation Blocks By: SharkPool (function (Scratch) { "use strict"; From fbe6aceecbf4c934cdd35ab09c2f43b2b7155b11 Mon Sep 17 00:00:00 2001 From: SharkPool-SP <139097378+SharkPool-SP@users.noreply.github.com> Date: Tue, 22 Aug 2023 21:58:44 -0700 Subject: [PATCH 03/30] Update time.js --- extensions/-SIPC-/time.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index 4d4d77360a..8c82453a3a 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -1,7 +1,7 @@ // Name: Time // ID: sipctime -// Old Description: Blocks for interacting with unix timestamps and other date strings. -// Updated Description: Blocks for Time, Date, and Time Zone calculations and interactions. +// Old Desc: Blocks for interacting with unix timestamps and other date strings. +// Description: Blocks for Time, Date, and Time Zone calculations and interactions. // Main Extension By: -SIPC- // Calculation Blocks By: SharkPool From 87330a848be9940c70dece914cae005c6bcccc05 Mon Sep 17 00:00:00 2001 From: SharkPool-SP <139097378+SharkPool-SP@users.noreply.github.com> Date: Thu, 24 Aug 2023 01:12:58 -0700 Subject: [PATCH 04/30] Update time.js --- extensions/-SIPC-/time.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index 8c82453a3a..41a14f1dad 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -2,7 +2,7 @@ // ID: sipctime // Old Desc: Blocks for interacting with unix timestamps and other date strings. // Description: Blocks for Time, Date, and Time Zone calculations and interactions. -// Main Extension By: -SIPC- +// By: -SIPC- // Calculation Blocks By: SharkPool (function (Scratch) { From b2492718ae542af91f5df35f81261efdd255e8e9 Mon Sep 17 00:00:00 2001 From: Muffin Date: Fri, 25 Aug 2023 00:59:21 -0500 Subject: [PATCH 05/30] a couple nitpicks, and format code --- extensions/-SIPC-/time.js | 214 +++++++++++++++++++------------------- 1 file changed, 105 insertions(+), 109 deletions(-) diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index 41a14f1dad..f786eb0204 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -1,9 +1,9 @@ // Name: Time // ID: sipctime // Old Desc: Blocks for interacting with unix timestamps and other date strings. -// Description: Blocks for Time, Date, and Time Zone calculations and interactions. +// Description: Blocks for times, dates, and time zones. // By: -SIPC- -// Calculation Blocks By: SharkPool +// By: SharkPool (function (Scratch) { "use strict"; @@ -25,20 +25,16 @@ menuIconURI, blockIconURI, blocks: [ - { - blockType: Scratch.BlockType.LABEL, - text: 'Time Conversions', - }, { opcode: "Timestamp", blockType: Scratch.BlockType.REPORTER, - text: "current timestamp", + text: "current unix timestamp", arguments: {}, }, { opcode: "timezone", blockType: Scratch.BlockType.REPORTER, - text: "current time zone", + text: "current time zone offset", arguments: {}, }, { @@ -81,91 +77,91 @@ }, { blockType: Scratch.BlockType.LABEL, - text: 'Time Calculations', + text: "Time Calculations", }, { - opcode: 'calculatetimedurationfromdate', + opcode: "calculatetimedurationfromdate", blockType: Scratch.BlockType.REPORTER, - text: 'time duration from [DATE] to current date in [TIME_MENU]', + text: "time duration from [DATE] to current date in [TIME_MENU]", arguments: { - DATE: { - type: Scratch.ArgumentType.STRING, - defaultValue: '2006-04-16' - }, - TIME_MENU: { - type: Scratch.ArgumentType.STRING, - menu: 'Time', - defaultValue: 'day' - }, - } + DATE: { + type: Scratch.ArgumentType.STRING, + defaultValue: "2006-04-16", + }, + TIME_MENU: { + type: Scratch.ArgumentType.STRING, + menu: "Time", + defaultValue: "day", + }, + }, }, { - opcode: 'calculatetimedurationfromtime', + opcode: "calculatetimedurationfromtime", blockType: Scratch.BlockType.REPORTER, - text: 'time duration from [START_HOUR]:[START_MINUTE] to current time in [TIME_MENU]', + text: "time duration from [START_HOUR]:[START_MINUTE] to current time in [TIME_MENU]", arguments: { - START_HOUR: { - type: Scratch.ArgumentType.NUMBER, - defaultValue: 0 - }, - START_MINUTE: { - type: Scratch.ArgumentType.NUMBER, - defaultValue: 0 - }, - TIME_MENU: { - type: Scratch.ArgumentType.STRING, - menu: 'Time', - defaultValue: 'hour' - }, - } + START_HOUR: { + type: Scratch.ArgumentType.NUMBER, + defaultValue: 0, + }, + START_MINUTE: { + type: Scratch.ArgumentType.NUMBER, + defaultValue: 0, + }, + TIME_MENU: { + type: Scratch.ArgumentType.STRING, + menu: "Time", + defaultValue: "hour", + }, + }, }, { - opcode: 'calculatetimedifference', + opcode: "calculatetimedifference", blockType: Scratch.BlockType.REPORTER, - text: 'difference between [START_TIME] and [END_TIME] in [TIME_MENU]', + text: "difference between [START_TIME] and [END_TIME] in [TIME_MENU]", arguments: { - START_TIME: { - type: Scratch.ArgumentType.STRING, - defaultValue: '00:00' - }, - END_TIME: { - type: Scratch.ArgumentType.STRING, - defaultValue: '00:00' - }, - TIME_MENU: { - type: Scratch.ArgumentType.STRING, - menu: 'Time', - defaultValue: 'hour' - }, - } + START_TIME: { + type: Scratch.ArgumentType.STRING, + defaultValue: "00:00", + }, + END_TIME: { + type: Scratch.ArgumentType.STRING, + defaultValue: "00:00", + }, + TIME_MENU: { + type: Scratch.ArgumentType.STRING, + menu: "Time", + defaultValue: "hour", + }, + }, }, { - opcode: 'converttotime', + opcode: "converttotime", blockType: Scratch.BlockType.REPORTER, - text: 'convert [VALUE] to time (day:hour:minute)', + text: "convert [VALUE] to time (day:hour:minute)", arguments: { - VALUE: { - type: Scratch.ArgumentType.NUMBER, - defaultValue: 0 - }, - } + VALUE: { + type: Scratch.ArgumentType.NUMBER, + defaultValue: 0, + }, + }, }, { - opcode: 'daysinmonth', + opcode: "daysinmonth", blockType: Scratch.BlockType.REPORTER, - text: 'number of days in [MONTH] [YEAR]', + text: "number of days in [MONTH] [YEAR]", arguments: { - MONTH: { - type: Scratch.ArgumentType.STRING, - menu: 'Months', - defaultValue: 'January' - }, - YEAR: { - type: Scratch.ArgumentType.STRING, - defaultValue: '2000' - }, - } - } + MONTH: { + type: Scratch.ArgumentType.STRING, + menu: "Months", + defaultValue: "January", + }, + YEAR: { + type: Scratch.ArgumentType.STRING, + defaultValue: "2000", + }, + }, + }, ], menus: { Time: { @@ -175,19 +171,19 @@ Months: { acceptReporters: true, items: [ - 'January', - 'February', - 'March', - 'April', - 'May', - 'June', - 'July', - 'August', - 'September', - 'October', - 'November', - 'December' - ] + "January", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September", + "October", + "November", + "December", + ], }, }, }; @@ -196,7 +192,7 @@ return Date.now(); } timezone() { - return "UTC+" + new Date().getTimezoneOffset() / -60; + return new Date().getTimezoneOffset() / -60; } Timedata(args) { args.timestamp = args.timestamp ? args.timestamp : null; @@ -256,17 +252,17 @@ const timeDiff = Math.abs(endDate.getTime() - startDate.getTime()); switch (timeMenu) { - case 'year': + case "year": return Math.floor(timeDiff / (1000 * 60 * 60 * 24 * 365)); - case 'month': + case "month": return Math.floor(timeDiff / (1000 * 60 * 60 * 24 * 30)); - case 'day': + case "day": return Math.floor(timeDiff / (1000 * 60 * 60 * 24)); - case 'hour': + case "hour": return Math.floor(timeDiff / (1000 * 60 * 60)); - case 'minute': + case "minute": return Math.floor(timeDiff / (1000 * 60)); - case 'second': + case "second": return Math.floor(timeDiff / 1000); } } @@ -295,10 +291,10 @@ const timeMenu = args.TIME_MENU; const startDate = new Date(); const endDate = new Date(); - const startHour = parseInt(startTime.split(':')[0]); - const startMinute = parseInt(startTime.split(':')[1]); - const endHour = parseInt(endTime.split(':')[0]); - const endMinute = parseInt(endTime.split(':')[1]); + const startHour = parseInt(startTime.split(":")[0]); + const startMinute = parseInt(startTime.split(":")[1]); + const endHour = parseInt(endTime.split(":")[0]); + const endMinute = parseInt(endTime.split(":")[1]); startDate.setHours(startHour, startMinute, 0, 0); endDate.setHours(endHour, endMinute, 0, 0); return this.calculateTimeDifference(startDate, endDate, timeMenu); @@ -324,18 +320,18 @@ _getMonthIndex(month) { const months = [ - 'January', - 'February', - 'March', - 'April', - 'May', - 'June', - 'July', - 'August', - 'September', - 'October', - 'November', - 'December' + "January", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September", + "October", + "November", + "December", ]; return months.indexOf(month); } From fd0f2b152fd5ae8fbf55c3fa26b323f910217a09 Mon Sep 17 00:00:00 2001 From: Muffin Date: Fri, 25 Aug 2023 01:03:19 -0500 Subject: [PATCH 06/30] unchange timezone --- extensions/-SIPC-/time.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index f786eb0204..00dd778764 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -34,7 +34,7 @@ { opcode: "timezone", blockType: Scratch.BlockType.REPORTER, - text: "current time zone offset", + text: "current time zone", arguments: {}, }, { @@ -192,7 +192,7 @@ return Date.now(); } timezone() { - return new Date().getTimezoneOffset() / -60; + return "UTC+" + new Date().getTimezoneOffset() / -60; } Timedata(args) { args.timestamp = args.timestamp ? args.timestamp : null; From 924e7039a45bb1b271ab6ef9721a88022e667a46 Mon Sep 17 00:00:00 2001 From: SharkPool-SP <139097378+SharkPool-SP@users.noreply.github.com> Date: Fri, 25 Aug 2023 21:24:42 -0700 Subject: [PATCH 07/30] Fix time.js Fixed Stuff --- extensions/-SIPC-/time.js | 59 ++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index 00dd778764..02ad6905db 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -34,7 +34,7 @@ { opcode: "timezone", blockType: Scratch.BlockType.REPORTER, - text: "current time zone", + text: "current time zone offset", arguments: {}, }, { @@ -82,7 +82,7 @@ { opcode: "calculatetimedurationfromdate", blockType: Scratch.BlockType.REPORTER, - text: "time duration from [DATE] to current date in [TIME_MENU]", + text: "difference between [DATE] to current date in [TIME_MENU]", arguments: { DATE: { type: Scratch.ArgumentType.STRING, @@ -98,15 +98,11 @@ { opcode: "calculatetimedurationfromtime", blockType: Scratch.BlockType.REPORTER, - text: "time duration from [START_HOUR]:[START_MINUTE] to current time in [TIME_MENU]", + text: "difference between [START_TIME] to current time in [TIME_MENU]", arguments: { - START_HOUR: { - type: Scratch.ArgumentType.NUMBER, - defaultValue: 0, - }, - START_MINUTE: { - type: Scratch.ArgumentType.NUMBER, - defaultValue: 0, + START_TIME: { + type: Scratch.ArgumentType.STRING, + defaultValue: "00:00", }, TIME_MENU: { type: Scratch.ArgumentType.STRING, @@ -157,7 +153,7 @@ defaultValue: "January", }, YEAR: { - type: Scratch.ArgumentType.STRING, + type: Scratch.ArgumentType.NUMBER, defaultValue: "2000", }, }, @@ -192,7 +188,7 @@ return Date.now(); } timezone() { - return "UTC+" + new Date().getTimezoneOffset() / -60; + return new Date().getTimezoneOffset() / -60; } Timedata(args) { args.timestamp = args.timestamp ? args.timestamp : null; @@ -264,6 +260,8 @@ return Math.floor(timeDiff / (1000 * 60)); case "second": return Math.floor(timeDiff / 1000); + default: + return "Invalid Menu Input"; } } @@ -272,17 +270,28 @@ const timeMenu = args.TIME_MENU; const startDate = new Date(dateString); const endDate = new Date(); - return this.calculateTimeDifference(startDate, endDate, timeMenu); + const difference = this.calculateTimeDifference(startDate, endDate, timeMenu); + if (isNaN(difference)) { + return "Invalid Time Input"; + } else { + return difference; + } } calculatetimedurationfromtime(args) { - const startHour = args.START_HOUR ? args.START_HOUR : null; - const startMinute = args.START_MINUTE ? args.START_MINUTE : null; + const startTime = args.START_TIME ? args.START_TIME : null; const timeMenu = args.TIME_MENU; + const [startHour, startMinute] = startTime.split(":"); const startDate = new Date(); - startDate.setHours(startHour, startMinute, 0, 0); + startDate.setHours(parseInt(startHour), parseInt(startMinute), 0, 0); const endDate = new Date(); - return this.calculateTimeDifference(startDate, endDate, timeMenu); + const difference = this.calculateTimeDifference(startDate, endDate, timeMenu); + + if (isNaN(difference)) { + return "Invalid Time Input"; + } else { + return difference; + } } calculatetimedifference(args) { @@ -297,7 +306,13 @@ const endMinute = parseInt(endTime.split(":")[1]); startDate.setHours(startHour, startMinute, 0, 0); endDate.setHours(endHour, endMinute, 0, 0); - return this.calculateTimeDifference(startDate, endDate, timeMenu); + + const difference = this.calculateTimeDifference(startDate, endDate, timeMenu); + if (isNaN(difference)) { + return "Invalid Time Input"; + } else { + return difference; + } } converttotime(args) { @@ -314,7 +329,13 @@ daysinmonth(args) { const month = args.MONTH; const year = args.YEAR ? args.YEAR : null; - const date = new Date(year, this._getMonthIndex(month) + 1, 0); + const monthIndex = this._getMonthIndex(month); + + if (monthIndex === -1) { + return "Invalid month"; + } + + const date = new Date(year, monthIndex + 1, 0); return date.getDate(); } From f6c7351246c028d6ac84cfb8ae7ae2ade66a3cce Mon Sep 17 00:00:00 2001 From: SharkPool-SP <139097378+SharkPool-SP@users.noreply.github.com> Date: Sat, 2 Sep 2023 22:40:40 -0700 Subject: [PATCH 08/30] Update time.js --- extensions/-SIPC-/time.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index 02ad6905db..8d1a79ade8 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -1,9 +1,10 @@ // Name: Time // ID: sipctime -// Old Desc: Blocks for interacting with unix timestamps and other date strings. // Description: Blocks for times, dates, and time zones. // By: -SIPC- -// By: SharkPool + +// Old Desc: Blocks for interacting with unix timestamps and other date strings. +// Calculation Blocks By: SharkPool (function (Scratch) { "use strict"; From ba09449f415c3f389b7f69bf3f6806a989975278 Mon Sep 17 00:00:00 2001 From: SharkPool-SP <139097378+SharkPool-SP@users.noreply.github.com> Date: Wed, 6 Sep 2023 22:25:13 -0700 Subject: [PATCH 09/30] Update time.js --- extensions/-SIPC-/time.js | 91 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 85 insertions(+), 6 deletions(-) diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index 8d1a79ade8..a84b1ba315 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -159,6 +159,36 @@ }, }, }, + + '---', + + { + opcode: "countdownReport", + blockType: Scratch.BlockType.REPORTER, + text: "countdown to [TIME] in [MENU]", + arguments: { + TIME: { + type: Scratch.ArgumentType.STRING, + defaultValue: '2007-03-14 09:34:00', + }, + MENU: { + type: Scratch.ArgumentType.STRING, + menu: "Time", + defaultValue: "hour", + }, + }, + }, + { + opcode: "countdownBoolean", + blockType: Scratch.BlockType.BOOLEAN, + text: "countdown to [TIME] reached?", + arguments: { + TIME: { + type: Scratch.ArgumentType.STRING, + defaultValue: '2007-03-14 09:34:00', + }, + }, + }, ], menus: { Time: { @@ -250,17 +280,17 @@ switch (timeMenu) { case "year": - return Math.floor(timeDiff / (1000 * 60 * 60 * 24 * 365)); + return Math.round(timeDifference / 946080000000); case "month": - return Math.floor(timeDiff / (1000 * 60 * 60 * 24 * 30)); + return Math.round(timeDifference / 2592000000); case "day": - return Math.floor(timeDiff / (1000 * 60 * 60 * 24)); + return Math.round(timeDifference / 86400000); case "hour": - return Math.floor(timeDiff / (1000 * 60 * 60)); + return Math.round(timeDifference / 3600000); case "minute": - return Math.floor(timeDiff / (1000 * 60)); + return Math.round(timeDifference / 60000); case "second": - return Math.floor(timeDiff / 1000); + return Math.round(timeDifference / 1000); default: return "Invalid Menu Input"; } @@ -357,6 +387,55 @@ ]; return months.indexOf(month); } + + countdownReport(args) { + const timeMenu = args.MENU; + const endDate = Date.now(); + + const dateTimeParts = args.TIME.split(/[- :]/); + const year = parseInt(dateTimeParts[0]); + const month = parseInt(dateTimeParts[1]) - 1; + const day = parseInt(dateTimeParts[2]); + const hour = parseInt(dateTimeParts[3]); + const minute = parseInt(dateTimeParts[4]); + const second = parseInt(dateTimeParts[5]); + + const startDate = new Date(year, month, day, hour, minute, second).getTime(); + const timeDifference = startDate - endDate; + + switch (timeMenu) { + case "year": + return Math.round(timeDifference / 946080000000); + case "month": + return Math.round(timeDifference / 2592000000); + case "day": + return Math.round(timeDifference / 86400000); + case "hour": + return Math.round(timeDifference / 3600000); + case "minute": + return Math.round(timeDifference / 60000); + case "second": + return Math.round(timeDifference / 1000); + default: + return "Invalid Menu Input"; + } + } + + countdownBoolean(args) { + const endDate = Date.now(); + + const dateTimeParts = args.TIME.split(/[- :]/); + const year = parseInt(dateTimeParts[0]); + const month = parseInt(dateTimeParts[1]) - 1; + const day = parseInt(dateTimeParts[2]); + const hour = parseInt(dateTimeParts[3]); + const minute = parseInt(dateTimeParts[4]); + const second = parseInt(dateTimeParts[5]); + + const startDate = new Date(year, month, day, hour, minute, second).getTime(); + const timeDifference = startDate - endDate; + return (timeDifference <= 0); + } } Scratch.extensions.register(new Time()); })(Scratch); From 65c21d8b977f7b9bd421768c1ed97b3e3277866a Mon Sep 17 00:00:00 2001 From: SharkPool-SP <139097378+SharkPool-SP@users.noreply.github.com> Date: Wed, 6 Sep 2023 22:27:23 -0700 Subject: [PATCH 10/30] Update time.js --- extensions/-SIPC-/time.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index a84b1ba315..75f02b517c 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -280,17 +280,17 @@ switch (timeMenu) { case "year": - return Math.round(timeDifference / 946080000000); + return Math.round(timeDiff / 946080000000); case "month": - return Math.round(timeDifference / 2592000000); + return Math.round(timeDiff / 2592000000); case "day": - return Math.round(timeDifference / 86400000); + return Math.round(timeDiff / 86400000); case "hour": - return Math.round(timeDifference / 3600000); + return Math.round(timeDiff / 3600000); case "minute": - return Math.round(timeDifference / 60000); + return Math.round(timeDiff / 60000); case "second": - return Math.round(timeDifference / 1000); + return Math.round(timeDiff / 1000); default: return "Invalid Menu Input"; } From cba87ee3c80f872469c39ce79f7139620e7e9962 Mon Sep 17 00:00:00 2001 From: SharkPool-SP <139097378+SharkPool-SP@users.noreply.github.com> Date: Mon, 11 Sep 2023 22:29:18 -0700 Subject: [PATCH 11/30] Update time.js --- extensions/-SIPC-/time.js | 175 +++++++++++++++++++++++++------------- 1 file changed, 114 insertions(+), 61 deletions(-) diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index 75f02b517c..affc0485fd 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -83,16 +83,16 @@ { opcode: "calculatetimedurationfromdate", blockType: Scratch.BlockType.REPORTER, - text: "difference between [DATE] to current date in [TIME_MENU]", + text: "difference between [DATE] to current datetime in [TIME_MENU]", arguments: { DATE: { type: Scratch.ArgumentType.STRING, - defaultValue: "2006-04-16", + defaultValue: "2007-03-14 09:34:00", }, TIME_MENU: { type: Scratch.ArgumentType.STRING, menu: "Time", - defaultValue: "day", + defaultValue: "hour", }, }, }, @@ -103,7 +103,27 @@ arguments: { START_TIME: { type: Scratch.ArgumentType.STRING, - defaultValue: "00:00", + defaultValue: "00:00:00", + }, + TIME_MENU: { + type: Scratch.ArgumentType.STRING, + menu: "Time", + defaultValue: "hour", + }, + }, + }, + { + opcode: "calculatetimedurationfromstamp", + blockType: Scratch.BlockType.REPORTER, + text: "difference between [START_TIME] and [END_TIME] in [TIME_MENU]", + arguments: { + START_TIME: { + type: Scratch.ArgumentType.STRING, + defaultValue: "2007-03-14 09:34:00", + }, + END_TIME: { + type: Scratch.ArgumentType.STRING, + defaultValue: "2016-07-21 15:03:00", }, TIME_MENU: { type: Scratch.ArgumentType.STRING, @@ -132,10 +152,13 @@ }, }, }, + + '---', + { opcode: "converttotime", blockType: Scratch.BlockType.REPORTER, - text: "convert [VALUE] to time (day:hour:minute)", + text: "convert [VALUE] to time (hour:minute:second)", arguments: { VALUE: { type: Scratch.ArgumentType.NUMBER, @@ -143,6 +166,22 @@ }, }, }, + { + opcode: "convertToValue", + blockType: Scratch.BlockType.REPORTER, + text: "convert [VALUE] to [TIME]", + arguments: { + VALUE: { + type: Scratch.ArgumentType.STRING, + defaultValue: "1970-01-01 00:00:00", + }, + TIME: { + type: Scratch.ArgumentType.STRING, + menu: "Time", + defaultValue: "hour", + }, + }, + }, { opcode: "daysinmonth", blockType: Scratch.BlockType.REPORTER, @@ -275,22 +314,22 @@ return timestamp; } - calculateTimeDifference(startDate, endDate, timeMenu) { - const timeDiff = Math.abs(endDate.getTime() - startDate.getTime()); - + calculateTimeDifference(startDate, endDate, timeMenu, abs) { + let timeDiff = endDate.getTime() - startDate.getTime(); + timeDiff = (abs) ? Math.abs(timeDiff) : timeDiff * -1; switch (timeMenu) { case "year": - return Math.round(timeDiff / 946080000000); + return (timeDiff / 946080000000); case "month": - return Math.round(timeDiff / 2592000000); + return (timeDiff / 2592000000); case "day": - return Math.round(timeDiff / 86400000); + return (timeDiff / 86400000); case "hour": - return Math.round(timeDiff / 3600000); + return (timeDiff / 3600000); case "minute": - return Math.round(timeDiff / 60000); + return (timeDiff / 60000); case "second": - return Math.round(timeDiff / 1000); + return (timeDiff / 1000); default: return "Invalid Menu Input"; } @@ -301,7 +340,21 @@ const timeMenu = args.TIME_MENU; const startDate = new Date(dateString); const endDate = new Date(); - const difference = this.calculateTimeDifference(startDate, endDate, timeMenu); + const difference = this.calculateTimeDifference(startDate, endDate, timeMenu, true); + if (isNaN(difference)) { + return "Invalid Time Input"; + } else { + return difference; + } + } + + calculatetimedurationfromstamp(args) { + const dateString = args.START_TIME ? args.START_TIME : null; + const endDateString = args.END_TIME ? args.END_TIME : null; + const timeMenu = args.TIME_MENU; + const startDate = new Date(dateString); + const endDate = new Date(endDateString); + const difference = this.calculateTimeDifference(startDate, endDate, timeMenu, true); if (isNaN(difference)) { return "Invalid Time Input"; } else { @@ -316,7 +369,7 @@ const startDate = new Date(); startDate.setHours(parseInt(startHour), parseInt(startMinute), 0, 0); const endDate = new Date(); - const difference = this.calculateTimeDifference(startDate, endDate, timeMenu); + const difference = this.calculateTimeDifference(startDate, endDate, timeMenu, true); if (isNaN(difference)) { return "Invalid Time Input"; @@ -338,7 +391,7 @@ startDate.setHours(startHour, startMinute, 0, 0); endDate.setHours(endHour, endMinute, 0, 0); - const difference = this.calculateTimeDifference(startDate, endDate, timeMenu); + const difference = this.calculateTimeDifference(startDate, endDate, timeMenu, true); if (isNaN(difference)) { return "Invalid Time Input"; } else { @@ -347,16 +400,44 @@ } converttotime(args) { - const value = args.VALUE ? args.VALUE : 0; - const seconds = Math.floor(value); - const minutes = Math.floor(seconds / 60); - const hours = Math.floor(minutes / 60); - const days = Math.floor(hours / 24); + const timestamp = args.VALUE ? args.VALUE : 0; + const seconds = timestamp % 60; + const minutes = Math.round((timestamp / 60) % 60); + const hours = Math.round((timestamp / 3600) % 24); - const timeString = `${hours % 24}:${minutes % 60}:${seconds % 60}`; + const timeString = `${hours}:${minutes}:${seconds}`; return timeString; } + convertToValue(args) { + const dateString = args.VALUE ? args.VALUE : null; + let date = new Date(dateString); + date = Math.round(date.getTime() / 1000) - 28800; + + switch (args.TIME) { + case "year": + return (date / 31536000); + case "month": + return (date / 2592000); + case "day": + return (date / 86400); + case "hour": + return (date / 3600); + case "minute": + return (date / 60); + case "second": + return date; + default: + return "Invalid Menu Input"; + } + + if (isNaN(date.getTime())) { + return "Invalid Time Input"; + } else { + return date; + } + } + daysinmonth(args) { const month = args.MONTH; const year = args.YEAR ? args.YEAR : null; @@ -390,49 +471,21 @@ countdownReport(args) { const timeMenu = args.MENU; - const endDate = Date.now(); - - const dateTimeParts = args.TIME.split(/[- :]/); - const year = parseInt(dateTimeParts[0]); - const month = parseInt(dateTimeParts[1]) - 1; - const day = parseInt(dateTimeParts[2]); - const hour = parseInt(dateTimeParts[3]); - const minute = parseInt(dateTimeParts[4]); - const second = parseInt(dateTimeParts[5]); - - const startDate = new Date(year, month, day, hour, minute, second).getTime(); - const timeDifference = startDate - endDate; - - switch (timeMenu) { - case "year": - return Math.round(timeDifference / 946080000000); - case "month": - return Math.round(timeDifference / 2592000000); - case "day": - return Math.round(timeDifference / 86400000); - case "hour": - return Math.round(timeDifference / 3600000); - case "minute": - return Math.round(timeDifference / 60000); - case "second": - return Math.round(timeDifference / 1000); - default: - return "Invalid Menu Input"; + const endDate = new Date(); + const dateString = args.TIME ? args.TIME : null; + const startDate = new Date(dateString); + const difference = this.calculateTimeDifference(startDate, endDate, timeMenu, false); + if (isNaN(difference)) { + return "Invalid Time Input"; + } else { + return difference; } } countdownBoolean(args) { const endDate = Date.now(); - - const dateTimeParts = args.TIME.split(/[- :]/); - const year = parseInt(dateTimeParts[0]); - const month = parseInt(dateTimeParts[1]) - 1; - const day = parseInt(dateTimeParts[2]); - const hour = parseInt(dateTimeParts[3]); - const minute = parseInt(dateTimeParts[4]); - const second = parseInt(dateTimeParts[5]); - - const startDate = new Date(year, month, day, hour, minute, second).getTime(); + const dateString = args.TIME ? args.TIME : null; + const startDate = new Date(dateString); const timeDifference = startDate - endDate; return (timeDifference <= 0); } From b11233906bc1f377e106682121c02af0749f9e8f Mon Sep 17 00:00:00 2001 From: SharkPool-SP <139097378+SharkPool-SP@users.noreply.github.com> Date: Mon, 11 Sep 2023 22:33:20 -0700 Subject: [PATCH 12/30] Update time.js --- extensions/-SIPC-/time.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index affc0485fd..54d58c5daa 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -430,12 +430,6 @@ default: return "Invalid Menu Input"; } - - if (isNaN(date.getTime())) { - return "Invalid Time Input"; - } else { - return date; - } } daysinmonth(args) { From 21975e21b9ac1418b36e0288e576ec9fe248bed3 Mon Sep 17 00:00:00 2001 From: SharkPool-SP <139097378+SharkPool-SP@users.noreply.github.com> Date: Sat, 16 Sep 2023 20:58:38 -0700 Subject: [PATCH 13/30] Update time.js --- extensions/-SIPC-/time.js | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index 54d58c5daa..419b709699 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -152,6 +152,26 @@ }, }, }, + { + opcode: "evaluateTime", + blockType: Scratch.BlockType.REPORTER, + text: "[MATH] [START_TIME] and [END_TIME]", + arguments: { + START_TIME: { + type: Scratch.ArgumentType.STRING, + defaultValue: "1970-01-01 00:00:00", + }, + END_TIME: { + type: Scratch.ArgumentType.STRING, + defaultValue: "2016-07-21 15:03:00", + }, + MATH: { + type: Scratch.ArgumentType.STRING, + menu: "MathType", + defaultValue: "add", + }, + }, + }, '---', @@ -234,6 +254,10 @@ acceptReporters: true, items: ["year", "month", "day", "hour", "minute", "second"], }, + MathType: { + acceptReporters: true, + items: ["add", "subtract"], + }, Months: { acceptReporters: true, items: [ @@ -483,6 +507,27 @@ const timeDifference = startDate - endDate; return (timeDifference <= 0); } + + evaluateTime(args) { + const startTimeString = args.START_TIME ? args.START_TIME : null; + const endTimeString = args.END_TIME ? args.END_TIME : null; + const startDate = new Date(startTimeString); + const endDate = new Date(endTimeString); + + if (isNaN(startDate) || isNaN(endDate)) { + return "Invalid Time Input"; + } + + let timeDifference = ""; + if (args.MATH === "add") { + timeDifference = startDate.getTime() + endDate.getTime(); + } else { + timeDifference = startDate.getTime() - endDate.getTime(); + } + timeDifference = new Date(timeDifference); + timeDifference = `${timeDifference.getFullYear()}-${(timeDifference.getMonth() + 1).toString().padStart(2, '0')}-${timeDifference.getDate().toString().padStart(2, '0')} ${timeDifference.getHours().toString().padStart(2, '0')}:${timeDifference.getMinutes().toString().padStart(2, '0')}:${timeDifference.getSeconds().toString().padStart(2, '0')}`; + return timeDifference; + } } Scratch.extensions.register(new Time()); })(Scratch); From 2a449471d1f177dbc3dcae7740c8ef40e6f6f9f1 Mon Sep 17 00:00:00 2001 From: SharkPool-SP <139097378+SharkPool-SP@users.noreply.github.com> Date: Sat, 16 Sep 2023 21:09:59 -0700 Subject: [PATCH 14/30] Update time.js --- extensions/-SIPC-/time.js | 71 ++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 23 deletions(-) diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index 419b709699..e0eb3ad2b5 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -173,7 +173,7 @@ }, }, - '---', + "---", { opcode: "converttotime", @@ -219,7 +219,7 @@ }, }, - '---', + "---", { opcode: "countdownReport", @@ -228,7 +228,7 @@ arguments: { TIME: { type: Scratch.ArgumentType.STRING, - defaultValue: '2007-03-14 09:34:00', + defaultValue: "2007-03-14 09:34:00", }, MENU: { type: Scratch.ArgumentType.STRING, @@ -244,7 +244,7 @@ arguments: { TIME: { type: Scratch.ArgumentType.STRING, - defaultValue: '2007-03-14 09:34:00', + defaultValue: "2007-03-14 09:34:00", }, }, }, @@ -340,20 +340,20 @@ calculateTimeDifference(startDate, endDate, timeMenu, abs) { let timeDiff = endDate.getTime() - startDate.getTime(); - timeDiff = (abs) ? Math.abs(timeDiff) : timeDiff * -1; + timeDiff = abs ? Math.abs(timeDiff) : timeDiff * -1; switch (timeMenu) { case "year": - return (timeDiff / 946080000000); + return timeDiff / 946080000000; case "month": - return (timeDiff / 2592000000); + return timeDiff / 2592000000; case "day": - return (timeDiff / 86400000); + return timeDiff / 86400000; case "hour": - return (timeDiff / 3600000); + return timeDiff / 3600000; case "minute": - return (timeDiff / 60000); + return timeDiff / 60000; case "second": - return (timeDiff / 1000); + return timeDiff / 1000; default: return "Invalid Menu Input"; } @@ -364,7 +364,12 @@ const timeMenu = args.TIME_MENU; const startDate = new Date(dateString); const endDate = new Date(); - const difference = this.calculateTimeDifference(startDate, endDate, timeMenu, true); + const difference = this.calculateTimeDifference( + startDate, + endDate, + timeMenu, + true + ); if (isNaN(difference)) { return "Invalid Time Input"; } else { @@ -378,7 +383,12 @@ const timeMenu = args.TIME_MENU; const startDate = new Date(dateString); const endDate = new Date(endDateString); - const difference = this.calculateTimeDifference(startDate, endDate, timeMenu, true); + const difference = this.calculateTimeDifference( + startDate, + endDate, + timeMenu, + true + ); if (isNaN(difference)) { return "Invalid Time Input"; } else { @@ -393,7 +403,12 @@ const startDate = new Date(); startDate.setHours(parseInt(startHour), parseInt(startMinute), 0, 0); const endDate = new Date(); - const difference = this.calculateTimeDifference(startDate, endDate, timeMenu, true); + const difference = this.calculateTimeDifference( + startDate, + endDate, + timeMenu, + true + ); if (isNaN(difference)) { return "Invalid Time Input"; @@ -415,7 +430,12 @@ startDate.setHours(startHour, startMinute, 0, 0); endDate.setHours(endHour, endMinute, 0, 0); - const difference = this.calculateTimeDifference(startDate, endDate, timeMenu, true); + const difference = this.calculateTimeDifference( + startDate, + endDate, + timeMenu, + true + ); if (isNaN(difference)) { return "Invalid Time Input"; } else { @@ -440,15 +460,15 @@ switch (args.TIME) { case "year": - return (date / 31536000); + return date / 31536000; case "month": - return (date / 2592000); + return date / 2592000; case "day": - return (date / 86400); + return date / 86400; case "hour": - return (date / 3600); + return date / 3600; case "minute": - return (date / 60); + return date / 60; case "second": return date; default: @@ -492,7 +512,12 @@ const endDate = new Date(); const dateString = args.TIME ? args.TIME : null; const startDate = new Date(dateString); - const difference = this.calculateTimeDifference(startDate, endDate, timeMenu, false); + const difference = this.calculateTimeDifference( + startDate, + endDate, + timeMenu, + false + ); if (isNaN(difference)) { return "Invalid Time Input"; } else { @@ -505,7 +530,7 @@ const dateString = args.TIME ? args.TIME : null; const startDate = new Date(dateString); const timeDifference = startDate - endDate; - return (timeDifference <= 0); + return timeDifference <= 0; } evaluateTime(args) { @@ -525,7 +550,7 @@ timeDifference = startDate.getTime() - endDate.getTime(); } timeDifference = new Date(timeDifference); - timeDifference = `${timeDifference.getFullYear()}-${(timeDifference.getMonth() + 1).toString().padStart(2, '0')}-${timeDifference.getDate().toString().padStart(2, '0')} ${timeDifference.getHours().toString().padStart(2, '0')}:${timeDifference.getMinutes().toString().padStart(2, '0')}:${timeDifference.getSeconds().toString().padStart(2, '0')}`; + timeDifference = `${timeDifference.getFullYear()}-${(timeDifference.getMonth() + 1).toString().padStart(2, "0")}-${timeDifference.getDate().toString().padStart(2, "0")} ${timeDifference.getHours().toString().padStart(2, "0")}:${timeDifference.getMinutes().toString().padStart(2, "0")}:${timeDifference.getSeconds().toString().padStart(2, "0")}`; return timeDifference; } } From 115b61ea0982439e5cbb7a0f6f039bd78b53c4ea Mon Sep 17 00:00:00 2001 From: SharkPool-SP <139097378+SharkPool-SP@users.noreply.github.com> Date: Sat, 16 Sep 2023 21:13:51 -0700 Subject: [PATCH 15/30] Update time.js --- extensions/-SIPC-/time.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index e0eb3ad2b5..2be58ec035 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -10,9 +10,11 @@ "use strict"; const menuIconURI = + "data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHdpZHRoPSI4MS44ODU0IiBoZWlnaHQ9IjgwLjYwMzA4IiB2aWV3Qm94PSIwLDAsODEuODg1NCw4MC42MDMwOCI+PGcgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTE5OS4wNTczLC0xMzkuNjk4NDYpIj48ZyBkYXRhLXBhcGVyLWRhdGE9InsmcXVvdDtpc1BhaW50aW5nTGF5ZXImcXVvdDs6dHJ1ZX0iIGZpbGwtcnVsZT0ibm9uemVybyIgc3Ryb2tlPSJub25lIiBzdHJva2UtbGluZWNhcD0iYnV0dCIgc3Ryb2tlLWxpbmVqb2luPSJtaXRlciIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBzdHJva2UtZGFzaGFycmF5PSIiIHN0cm9rZS1kYXNob2Zmc2V0PSIwIiBzdHlsZT0ibWl4LWJsZW5kLW1vZGU6IG5vcm1hbCI+PHBhdGggZD0iTTI4MC45NDI3LDE4MGMwLDIyLjI1NzkyIC0xOC4zMzA2Nyw0MC4zMDE1NCAtNDAuOTQyNyw0MC4zMDE1NGMtMjIuNjEyMDMsMCAtNDAuOTQyNywtMTguMDQzNjEgLTQwLjk0MjcsLTQwLjMwMTU0YzAsLTIyLjI1NzkyIDE4LjMzMDY3LC00MC4zMDE1NCA0MC45NDI3LC00MC4zMDE1NGMyMi42MTIwMywwIDQwLjk0MjcsMTguMDQzNjEgNDAuOTQyNyw0MC4zMDE1NHoiIGZpbGw9IiNmZjgwMDAiIHN0cm9rZS13aWR0aD0iMCIvPjxwYXRoIGQ9Ik0yNjYuNTM0MzcsMTgwYzAsMTQuNjQxMjkgLTExLjg5MzA4LDI2LjUzNDM3IC0yNi41MzQzNywyNi41MzQzN2MtMTQuNjQxMjksMCAtMjYuNTM0MzcsLTExLjg5MzA4IC0yNi41MzQzNywtMjYuNTM0MzdjMCwtMTQuNjQxMjkgMTEuODkzMDgsLTI2LjUzNDM3IDI2LjUzNDM3LC0yNi41MzQzN2MxNC42NDEyOSwwIDI2LjUzNDM3LDExLjg5MzA4IDI2LjUzNDM3LDI2LjUzNDM3ek0yNTMuMjE5OCwxODUuOTcwMjNsLTExLjMyNDQ5LC02LjUzODgzdi0xNC41OTM5aC0zLjc5MDYydjE3LjA1NzgxaDAuNTIxMjFsMTIuNjk4NTksNy4zNDQzM3oiIGZpbGw9IiNmZmZmZmYiIHN0cm9rZS13aWR0aD0iMSIvPjwvZz48L2c+PC9zdmc+PCEtLXJvdGF0aW9uQ2VudGVyOjQwLjk0MjY5NjA1MzgwMTE0OjQwLjMwMTUzNTI2NTQ4NjcwNi0tPg=="; const blockIconURI = + "data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHdpZHRoPSIxNzUiIGhlaWdodD0iMTc1IiB2aWV3Qm94PSIwLDAsMTc1LDE3NSI+PGcgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTE1Mi41LC05Mi41KSI+PGcgZGF0YS1wYXBlci1kYXRhPSJ7JnF1b3Q7aXNQYWludGluZ0xheWVyJnF1b3Q7OnRydWV9IiBmaWxsPSIjZmZmZmZmIiBmaWxsLXJ1bGU9Im5vbnplcm8iIHN0cm9rZT0ibm9uZSIgc3Ryb2tlLXdpZHRoPSIxIiBzdHJva2UtbGluZWNhcD0iYnV0dCIgc3Ryb2tlLWxpbmVqb2luPSJtaXRlciIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBzdHJva2UtZGFzaGFycmF5PSIiIHN0cm9rZS1kYXNob2Zmc2V0PSIwIiBzdHlsZT0ibWl4LWJsZW5kLW1vZGU6IG5vcm1hbCI+PHBhdGggZD0iTTMyNy41LDE4MGMwLDQ4LjI4MTI1IC0zOS4yMTg3NSw4Ny41IC04Ny41LDg3LjVjLTQ4LjI4MTI1LDAgLTg3LjUsLTM5LjIxODc1IC04Ny41LC04Ny41YzAsLTQ4LjI4MTI1IDM5LjIxODc1LC04Ny41IDg3LjUsLTg3LjVjNDguMjgxMjUsMCA4Ny41LDM5LjIxODc1IDg3LjUsODcuNXpNMjgzLjU5Mzc1LDE5OS42ODc1bC0zNy4zNDM3NSwtMjEuNTYyNXYtNDguMTI1aC0xMi41djU2LjI1aDEuNzE4NzVsNDEuODc1LDI0LjIxODc1eiIvPjwvZz48L2c+PC9zdmc+PCEtLXJvdGF0aW9uQ2VudGVyOjg3LjU6ODcuNS0tPg=="; class Time { From 84f1cd9c0aaf61e1739cb16d1f68befd2af23629 Mon Sep 17 00:00:00 2001 From: SharkPool-SP <139097378+SharkPool-SP@users.noreply.github.com> Date: Sat, 16 Sep 2023 21:15:56 -0700 Subject: [PATCH 16/30] Update time.js --- extensions/-SIPC-/time.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index 2be58ec035..bf8e843710 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -551,9 +551,16 @@ } else { timeDifference = startDate.getTime() - endDate.getTime(); } - timeDifference = new Date(timeDifference); - timeDifference = `${timeDifference.getFullYear()}-${(timeDifference.getMonth() + 1).toString().padStart(2, "0")}-${timeDifference.getDate().toString().padStart(2, "0")} ${timeDifference.getHours().toString().padStart(2, "0")}:${timeDifference.getMinutes().toString().padStart(2, "0")}:${timeDifference.getSeconds().toString().padStart(2, "0")}`; - return timeDifference; + const resultDate = new Date(timeDifference); + const year = resultDate.getFullYear(); + const month = String(resultDate.getMonth() + 1).padStart(2, '0'); + const day = String(resultDate.getDate()).padStart(2, '0'); + const hours = String(resultDate.getHours()).padStart(2, '0'); + const minutes = String(resultDate.getMinutes()).padStart(2, '0'); + const seconds = String(resultDate.getSeconds()).padStart(2, '0'); + + const formattedResult = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; + return formattedResult; } } Scratch.extensions.register(new Time()); From 866298240faf746c10fff5af7f861011a5336f52 Mon Sep 17 00:00:00 2001 From: SharkPool-SP <139097378+SharkPool-SP@users.noreply.github.com> Date: Sat, 16 Sep 2023 21:25:27 -0700 Subject: [PATCH 17/30] Update time.js --- extensions/-SIPC-/time.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index bf8e843710..5cecb63187 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -10,11 +10,9 @@ "use strict"; const menuIconURI = - "data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHdpZHRoPSI4MS44ODU0IiBoZWlnaHQ9IjgwLjYwMzA4IiB2aWV3Qm94PSIwLDAsODEuODg1NCw4MC42MDMwOCI+PGcgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTE5OS4wNTczLC0xMzkuNjk4NDYpIj48ZyBkYXRhLXBhcGVyLWRhdGE9InsmcXVvdDtpc1BhaW50aW5nTGF5ZXImcXVvdDs6dHJ1ZX0iIGZpbGwtcnVsZT0ibm9uemVybyIgc3Ryb2tlPSJub25lIiBzdHJva2UtbGluZWNhcD0iYnV0dCIgc3Ryb2tlLWxpbmVqb2luPSJtaXRlciIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBzdHJva2UtZGFzaGFycmF5PSIiIHN0cm9rZS1kYXNob2Zmc2V0PSIwIiBzdHlsZT0ibWl4LWJsZW5kLW1vZGU6IG5vcm1hbCI+PHBhdGggZD0iTTI4MC45NDI3LDE4MGMwLDIyLjI1NzkyIC0xOC4zMzA2Nyw0MC4zMDE1NCAtNDAuOTQyNyw0MC4zMDE1NGMtMjIuNjEyMDMsMCAtNDAuOTQyNywtMTguMDQzNjEgLTQwLjk0MjcsLTQwLjMwMTU0YzAsLTIyLjI1NzkyIDE4LjMzMDY3LC00MC4zMDE1NCA0MC45NDI3LC00MC4zMDE1NGMyMi42MTIwMywwIDQwLjk0MjcsMTguMDQzNjEgNDAuOTQyNyw0MC4zMDE1NHoiIGZpbGw9IiNmZjgwMDAiIHN0cm9rZS13aWR0aD0iMCIvPjxwYXRoIGQ9Ik0yNjYuNTM0MzcsMTgwYzAsMTQuNjQxMjkgLTExLjg5MzA4LDI2LjUzNDM3IC0yNi41MzQzNywyNi41MzQzN2MtMTQuNjQxMjksMCAtMjYuNTM0MzcsLTExLjg5MzA4IC0yNi41MzQzNywtMjYuNTM0MzdjMCwtMTQuNjQxMjkgMTEuODkzMDgsLTI2LjUzNDM3IDI2LjUzNDM3LC0yNi41MzQzN2MxNC42NDEyOSwwIDI2LjUzNDM3LDExLjg5MzA4IDI2LjUzNDM3LDI2LjUzNDM3ek0yNTMuMjE5OCwxODUuOTcwMjNsLTExLjMyNDQ5LC02LjUzODgzdi0xNC41OTM5aC0zLjc5MDYydjE3LjA1NzgxaDAuNTIxMjFsMTIuNjk4NTksNy4zNDQzM3oiIGZpbGw9IiNmZmZmZmYiIHN0cm9rZS13aWR0aD0iMSIvPjwvZz48L2c+PC9zdmc+PCEtLXJvdGF0aW9uQ2VudGVyOjQwLjk0MjY5NjA1MzgwMTE0OjQwLjMwMTUzNTI2NTQ4NjcwNi0tPg=="; const blockIconURI = - "data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHdpZHRoPSIxNzUiIGhlaWdodD0iMTc1IiB2aWV3Qm94PSIwLDAsMTc1LDE3NSI+PGcgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTE1Mi41LC05Mi41KSI+PGcgZGF0YS1wYXBlci1kYXRhPSJ7JnF1b3Q7aXNQYWludGluZ0xheWVyJnF1b3Q7OnRydWV9IiBmaWxsPSIjZmZmZmZmIiBmaWxsLXJ1bGU9Im5vbnplcm8iIHN0cm9rZT0ibm9uZSIgc3Ryb2tlLXdpZHRoPSIxIiBzdHJva2UtbGluZWNhcD0iYnV0dCIgc3Ryb2tlLWxpbmVqb2luPSJtaXRlciIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBzdHJva2UtZGFzaGFycmF5PSIiIHN0cm9rZS1kYXNob2Zmc2V0PSIwIiBzdHlsZT0ibWl4LWJsZW5kLW1vZGU6IG5vcm1hbCI+PHBhdGggZD0iTTMyNy41LDE4MGMwLDQ4LjI4MTI1IC0zOS4yMTg3NSw4Ny41IC04Ny41LDg3LjVjLTQ4LjI4MTI1LDAgLTg3LjUsLTM5LjIxODc1IC04Ny41LC04Ny41YzAsLTQ4LjI4MTI1IDM5LjIxODc1LC04Ny41IDg3LjUsLTg3LjVjNDguMjgxMjUsMCA4Ny41LDM5LjIxODc1IDg3LjUsODcuNXpNMjgzLjU5Mzc1LDE5OS42ODc1bC0zNy4zNDM3NSwtMjEuNTYyNXYtNDguMTI1aC0xMi41djU2LjI1aDEuNzE4NzVsNDEuODc1LDI0LjIxODc1eiIvPjwvZz48L2c+PC9zdmc+PCEtLXJvdGF0aW9uQ2VudGVyOjg3LjU6ODcuNS0tPg=="; class Time { From fb665e8ef63ce78372a7f73b16ec985f2e1a1b33 Mon Sep 17 00:00:00 2001 From: SharkPool-SP <139097378+SharkPool-SP@users.noreply.github.com> Date: Sun, 17 Sep 2023 18:17:25 -0700 Subject: [PATCH 18/30] Update time.js --- extensions/-SIPC-/time.js | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index 5cecb63187..1d1b27d3d4 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -159,11 +159,11 @@ arguments: { START_TIME: { type: Scratch.ArgumentType.STRING, - defaultValue: "1970-01-01 00:00:00", + defaultValue: "2023-10-10 00:00:00", }, END_TIME: { type: Scratch.ArgumentType.STRING, - defaultValue: "2016-07-21 15:03:00", + defaultValue: "1970-01-01 00:10:00", }, MATH: { type: Scratch.ArgumentType.STRING, @@ -178,12 +178,17 @@ { opcode: "converttotime", blockType: Scratch.BlockType.REPORTER, - text: "convert [VALUE] to time (hour:minute:second)", + text: "convert [VALUE] seconds to [ROUND] time", arguments: { VALUE: { type: Scratch.ArgumentType.NUMBER, defaultValue: 0, }, + ROUND: { + type: Scratch.ArgumentType.NUMBER, + menu: "Round", + defaultValue: "exact", + }, }, }, { @@ -258,6 +263,10 @@ acceptReporters: true, items: ["add", "subtract"], }, + Round: { + acceptReporters: true, + items: ["rounded", "exact"], + }, Months: { acceptReporters: true, items: [ @@ -445,7 +454,7 @@ converttotime(args) { const timestamp = args.VALUE ? args.VALUE : 0; - const seconds = timestamp % 60; + const seconds = args.ROUND === "rounded" ? Math.round(timestamp % 60) : timestamp % 60; const minutes = Math.round((timestamp / 60) % 60); const hours = Math.round((timestamp / 3600) % 24); @@ -551,11 +560,12 @@ } const resultDate = new Date(timeDifference); const year = resultDate.getFullYear(); - const month = String(resultDate.getMonth() + 1).padStart(2, '0'); - const day = String(resultDate.getDate()).padStart(2, '0'); - const hours = String(resultDate.getHours()).padStart(2, '0'); - const minutes = String(resultDate.getMinutes()).padStart(2, '0'); - const seconds = String(resultDate.getSeconds()).padStart(2, '0'); + const month = String(resultDate.getMonth() + 1).padStart(2, "0"); + const day = String(resultDate.getDate()).padStart(2, "0"); + const changer = args.MATH === "add" ? 8 : -8; + const hours = String(resultDate.getHours() - changer).padStart(2, "0"); + const minutes = String(resultDate.getMinutes()).padStart(2, "0"); + const seconds = String(resultDate.getSeconds()).padStart(2, "0"); const formattedResult = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; return formattedResult; From 192e8481fee78711e18dc80eef7e509a7c00fced Mon Sep 17 00:00:00 2001 From: SharkPool-SP <139097378+SharkPool-SP@users.noreply.github.com> Date: Sun, 17 Sep 2023 20:30:28 -0700 Subject: [PATCH 19/30] Update time.js --- extensions/-SIPC-/time.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index 1d1b27d3d4..a08010cab3 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -563,7 +563,7 @@ const month = String(resultDate.getMonth() + 1).padStart(2, "0"); const day = String(resultDate.getDate()).padStart(2, "0"); const changer = args.MATH === "add" ? 8 : -8; - const hours = String(resultDate.getHours() - changer).padStart(2, "0"); + const hours = String(resultDate.getHours()).padStart(2, "0"); const minutes = String(resultDate.getMinutes()).padStart(2, "0"); const seconds = String(resultDate.getSeconds()).padStart(2, "0"); From 3688d623383e51c85468c47d58941c5acd56f65a Mon Sep 17 00:00:00 2001 From: SharkPool-SP <139097378+SharkPool-SP@users.noreply.github.com> Date: Sun, 17 Sep 2023 20:35:52 -0700 Subject: [PATCH 20/30] Update time.js --- extensions/-SIPC-/time.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index a08010cab3..e248ddc87f 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -454,7 +454,8 @@ converttotime(args) { const timestamp = args.VALUE ? args.VALUE : 0; - const seconds = args.ROUND === "rounded" ? Math.round(timestamp % 60) : timestamp % 60; + const seconds = args.ROUND === "rounded" ? + Math.round(timestamp % 60) : timestamp % 60; const minutes = Math.round((timestamp / 60) % 60); const hours = Math.round((timestamp / 3600) % 24); @@ -563,7 +564,7 @@ const month = String(resultDate.getMonth() + 1).padStart(2, "0"); const day = String(resultDate.getDate()).padStart(2, "0"); const changer = args.MATH === "add" ? 8 : -8; - const hours = String(resultDate.getHours()).padStart(2, "0"); + const hours = String(resultDate.getHours() - changer).padStart(2, "0"); const minutes = String(resultDate.getMinutes()).padStart(2, "0"); const seconds = String(resultDate.getSeconds()).padStart(2, "0"); From 701e52ee461f15c9590a0d32bf9e8965780e4781 Mon Sep 17 00:00:00 2001 From: SharkPool-SP <139097378+SharkPool-SP@users.noreply.github.com> Date: Wed, 20 Sep 2023 00:31:06 -0700 Subject: [PATCH 21/30] Update time.js --- extensions/-SIPC-/time.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index e248ddc87f..398c3100d2 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -454,8 +454,8 @@ converttotime(args) { const timestamp = args.VALUE ? args.VALUE : 0; - const seconds = args.ROUND === "rounded" ? - Math.round(timestamp % 60) : timestamp % 60; + const seconds = + args.ROUND === "rounded" ? Math.round(timestamp % 60) : timestamp % 60; const minutes = Math.round((timestamp / 60) % 60); const hours = Math.round((timestamp / 3600) % 24); From dfdce6f232bb070e4f452a5fabde906a16c29b4c Mon Sep 17 00:00:00 2001 From: SharkPool <139097378+SharkPool-SP@users.noreply.github.com> Date: Fri, 19 Jan 2024 14:43:30 -0800 Subject: [PATCH 22/30] Update time.js to Current Rubrics --- extensions/-SIPC-/time.js | 337 ++++++++++++-------------------------- 1 file changed, 104 insertions(+), 233 deletions(-) diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index 398c3100d2..bb3eeed557 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -29,14 +29,12 @@ { opcode: "Timestamp", blockType: Scratch.BlockType.REPORTER, - text: "current unix timestamp", - arguments: {}, + text: "current unix timestamp" }, { opcode: "timezone", blockType: Scratch.BlockType.REPORTER, - text: "current time zone offset", - arguments: {}, + text: "current time zone offset" }, { opcode: "Timedata", @@ -45,13 +43,12 @@ arguments: { timestamp: { type: Scratch.ArgumentType.NUMBER, - defaultValue: "1145141980000", + defaultValue: "1145141980000" }, Timedata: { type: Scratch.ArgumentType.STRING, - menu: "Time", - defaultValue: "year", - }, + menu: "Time" + } }, }, { @@ -61,7 +58,7 @@ arguments: { timestamp: { type: Scratch.ArgumentType.NUMBER, - defaultValue: "1145141980000", + defaultValue: "1145141980000" }, }, }, @@ -76,10 +73,7 @@ }, }, }, - { - blockType: Scratch.BlockType.LABEL, - text: "Time Calculations", - }, + { blockType: Scratch.BlockType.LABEL, text: "Time Calculations" }, { opcode: "calculatetimedurationfromdate", blockType: Scratch.BlockType.REPORTER, @@ -87,13 +81,12 @@ arguments: { DATE: { type: Scratch.ArgumentType.STRING, - defaultValue: "2007-03-14 09:34:00", + defaultValue: "2007-03-14 09:34:00" }, TIME_MENU: { type: Scratch.ArgumentType.STRING, - menu: "Time", - defaultValue: "hour", - }, + menu: "Time" + } }, }, { @@ -103,13 +96,12 @@ arguments: { START_TIME: { type: Scratch.ArgumentType.STRING, - defaultValue: "00:00:00", + defaultValue: "00:00:00" }, TIME_MENU: { type: Scratch.ArgumentType.STRING, - menu: "Time", - defaultValue: "hour", - }, + menu: "Time" + } }, }, { @@ -119,17 +111,16 @@ arguments: { START_TIME: { type: Scratch.ArgumentType.STRING, - defaultValue: "2007-03-14 09:34:00", + defaultValue: "2007-03-14 09:34:00" }, END_TIME: { type: Scratch.ArgumentType.STRING, - defaultValue: "2016-07-21 15:03:00", + defaultValue: "2016-07-21 15:03:00" }, TIME_MENU: { type: Scratch.ArgumentType.STRING, - menu: "Time", - defaultValue: "hour", - }, + menu: "Time" + } }, }, { @@ -139,17 +130,16 @@ arguments: { START_TIME: { type: Scratch.ArgumentType.STRING, - defaultValue: "00:00", + defaultValue: "00:00" }, END_TIME: { type: Scratch.ArgumentType.STRING, - defaultValue: "00:00", + defaultValue: "00:00" }, TIME_MENU: { type: Scratch.ArgumentType.STRING, - menu: "Time", - defaultValue: "hour", - }, + menu: "Time" + } }, }, { @@ -159,22 +149,19 @@ arguments: { START_TIME: { type: Scratch.ArgumentType.STRING, - defaultValue: "2023-10-10 00:00:00", + defaultValue: "2023-10-10 00:00:00" }, END_TIME: { type: Scratch.ArgumentType.STRING, - defaultValue: "1970-01-01 00:10:00", + defaultValue: "1970-01-01 00:10:00" }, MATH: { type: Scratch.ArgumentType.STRING, - menu: "MathType", - defaultValue: "add", - }, + menu: "MathType" + } }, }, - "---", - { opcode: "converttotime", blockType: Scratch.BlockType.REPORTER, @@ -182,13 +169,12 @@ arguments: { VALUE: { type: Scratch.ArgumentType.NUMBER, - defaultValue: 0, + defaultValue: 0 }, ROUND: { type: Scratch.ArgumentType.NUMBER, - menu: "Round", - defaultValue: "exact", - }, + menu: "Round" + } }, }, { @@ -198,13 +184,12 @@ arguments: { VALUE: { type: Scratch.ArgumentType.STRING, - defaultValue: "1970-01-01 00:00:00", + defaultValue: "1970-01-01 00:00:00" }, TIME: { type: Scratch.ArgumentType.STRING, - menu: "Time", - defaultValue: "hour", - }, + menu: "Time" + } }, }, { @@ -214,18 +199,15 @@ arguments: { MONTH: { type: Scratch.ArgumentType.STRING, - menu: "Months", - defaultValue: "January", + menu: "Months" }, YEAR: { type: Scratch.ArgumentType.NUMBER, - defaultValue: "2000", - }, + defaultValue: "2000" + } }, }, - "---", - { opcode: "countdownReport", blockType: Scratch.BlockType.REPORTER, @@ -237,9 +219,8 @@ }, MENU: { type: Scratch.ArgumentType.STRING, - menu: "Time", - defaultValue: "hour", - }, + menu: "Time" + } }, }, { @@ -249,8 +230,8 @@ arguments: { TIME: { type: Scratch.ArgumentType.STRING, - defaultValue: "2007-03-14 09:34:00", - }, + defaultValue: "2007-03-14 09:34:00" + } }, }, ], @@ -270,18 +251,9 @@ Months: { acceptReporters: true, items: [ - "January", - "February", - "March", - "April", - "May", - "June", - "July", - "August", - "September", - "October", - "November", - "December", + "January", "February", "March", "April", + "May", "June", "July", "August", + "September", "October", "November", "December", ], }, }, @@ -297,49 +269,25 @@ args.timestamp = args.timestamp ? args.timestamp : null; let date1 = new Date(Scratch.Cast.toNumber(args.timestamp)); switch (args.Timedata) { - case "year": - return date1.getFullYear(); - case "month": - return date1.getMonth() + 1 < 10 - ? "0" + (date1.getMonth() + 1) - : date1.getMonth() + 1; - case "day": - return date1.getDate() < 10 ? "0" + date1.getDate() : date1.getDate(); - case "hour": - return date1.getHours() < 10 - ? "0" + date1.getHours() - : date1.getHours(); - case "minute": - return date1.getMinutes() < 10 - ? "0" + date1.getMinutes() - : date1.getMinutes(); - case "second": - return date1.getSeconds() < 10 - ? "0" + date1.getSeconds() - : date1.getSeconds(); + case "year": return date1.getFullYear(); + case "month": return date1.getMonth() + 1 < 10 ? "0" + (date1.getMonth() + 1) : date1.getMonth() + 1; + case "day": return date1.getDate() < 10 ? "0" + date1.getDate() : date1.getDate(); + case "hour": return date1.getHours() < 10 ? "0" + date1.getHours() : date1.getHours(); + case "minute": return date1.getMinutes() < 10 ? "0" + date1.getMinutes() : date1.getMinutes(); + case "second": return date1.getSeconds() < 10 ? "0" + date1.getSeconds() : date1.getSeconds(); } return 0; } TimestampToTime({ timestamp }) { timestamp = timestamp ? timestamp : null; let date2 = new Date(timestamp); - let Y = date2.getFullYear() + "-"; - let M = - (date2.getMonth() + 1 < 10 - ? "0" + (date2.getMonth() + 1) - : date2.getMonth() + 1) + "-"; - let D = - (date2.getDate() < 10 ? "0" + date2.getDate() : date2.getDate()) + " "; - let h = - (date2.getHours() < 10 ? "0" + date2.getHours() : date2.getHours()) + - ":"; - let m = - (date2.getMinutes() < 10 - ? "0" + date2.getMinutes() - : date2.getMinutes()) + ":"; - let s = - date2.getSeconds() < 10 ? "0" + date2.getSeconds() : date2.getSeconds(); - return Y + M + D + h + m + s; + let Y = date2.getFullYear(); + let M = (date2.getMonth() + 1 < 10 ? "0" + (date2.getMonth() + 1) : date2.getMonth() + 1); + let D = (date2.getDate() < 10 ? "0" + date2.getDate() : date2.getDate()); + let h = (date2.getHours() < 10 ? "0" + date2.getHours() : date2.getHours()); + let m = (date2.getMinutes() < 10 ? "0" + date2.getMinutes() : date2.getMinutes()); + let s = date2.getSeconds() < 10 ? "0" + date2.getSeconds() : date2.getSeconds(); + return `${Y}-${M}-${D} ${h}:${m}:${s}`; } TimeToTimestamp({ time }) { let data3 = time; @@ -347,24 +295,18 @@ return timestamp; } + //SharkPools Section calculateTimeDifference(startDate, endDate, timeMenu, abs) { let timeDiff = endDate.getTime() - startDate.getTime(); timeDiff = abs ? Math.abs(timeDiff) : timeDiff * -1; switch (timeMenu) { - case "year": - return timeDiff / 946080000000; - case "month": - return timeDiff / 2592000000; - case "day": - return timeDiff / 86400000; - case "hour": - return timeDiff / 3600000; - case "minute": - return timeDiff / 60000; - case "second": - return timeDiff / 1000; - default: - return "Invalid Menu Input"; + case "year": return timeDiff / 946080000000; + case "month": return timeDiff / 2592000000; + case "day": return timeDiff / 86400000; + case "hour": return timeDiff / 3600000; + case "minute": return timeDiff / 60000; + case "second": return timeDiff / 1000; + default: return "Invalid Menu Input"; } } @@ -374,16 +316,10 @@ const startDate = new Date(dateString); const endDate = new Date(); const difference = this.calculateTimeDifference( - startDate, - endDate, - timeMenu, - true + startDate, endDate, timeMenu, true ); - if (isNaN(difference)) { - return "Invalid Time Input"; - } else { - return difference; - } + if (isNaN(difference)) return "Invalid Time Input"; + else return difference; } calculatetimedurationfromstamp(args) { @@ -393,16 +329,10 @@ const startDate = new Date(dateString); const endDate = new Date(endDateString); const difference = this.calculateTimeDifference( - startDate, - endDate, - timeMenu, - true + startDate, endDate, timeMenu, true ); - if (isNaN(difference)) { - return "Invalid Time Input"; - } else { - return difference; - } + if (isNaN(difference)) return "Invalid Time Input"; + else return difference; } calculatetimedurationfromtime(args) { @@ -413,23 +343,15 @@ startDate.setHours(parseInt(startHour), parseInt(startMinute), 0, 0); const endDate = new Date(); const difference = this.calculateTimeDifference( - startDate, - endDate, - timeMenu, - true + startDate, endDate, timeMenu, true ); - - if (isNaN(difference)) { - return "Invalid Time Input"; - } else { - return difference; - } + if (isNaN(difference)) return "Invalid Time Input"; + else return difference; } calculatetimedifference(args) { const startTime = args.START_TIME ? args.START_TIME : null; const endTime = args.END_TIME ? args.END_TIME : null; - const timeMenu = args.TIME_MENU; const startDate = new Date(); const endDate = new Date(); const startHour = parseInt(startTime.split(":")[0]); @@ -438,81 +360,49 @@ const endMinute = parseInt(endTime.split(":")[1]); startDate.setHours(startHour, startMinute, 0, 0); endDate.setHours(endHour, endMinute, 0, 0); - const difference = this.calculateTimeDifference( - startDate, - endDate, - timeMenu, - true + startDate, endDate, args.TIME_MENU, true ); - if (isNaN(difference)) { - return "Invalid Time Input"; - } else { - return difference; - } + if (isNaN(difference)) return "Invalid Time Input"; + else return difference; } converttotime(args) { - const timestamp = args.VALUE ? args.VALUE : 0; - const seconds = - args.ROUND === "rounded" ? Math.round(timestamp % 60) : timestamp % 60; - const minutes = Math.round((timestamp / 60) % 60); - const hours = Math.round((timestamp / 3600) % 24); - - const timeString = `${hours}:${minutes}:${seconds}`; - return timeString; + const tStamp = args.VALUE ? args.VALUE : 0; + const seconds = args.ROUND === "rounded" ? Math.round(tStamp % 60) : tStamp % 60; + const minutes = Math.round((tStamp / 60) % 60); + const hours = Math.round((tStamp / 3600) % 24); + return `${hours}:${minutes}:${seconds}`; } convertToValue(args) { - const dateString = args.VALUE ? args.VALUE : null; - let date = new Date(dateString); + let date = new Date(args.VALUE ? args.VALUE : null); date = Math.round(date.getTime() / 1000) - 28800; - switch (args.TIME) { - case "year": - return date / 31536000; - case "month": - return date / 2592000; - case "day": - return date / 86400; - case "hour": - return date / 3600; - case "minute": - return date / 60; - case "second": - return date; - default: - return "Invalid Menu Input"; + case "year": return date / 31536000; + case "month": return date / 2592000; + case "day": return date / 86400; + case "hour": return date / 3600; + case "minute": return date / 60; + case "second": return date; + default: return "Invalid Menu Input"; } } daysinmonth(args) { - const month = args.MONTH; const year = args.YEAR ? args.YEAR : null; - const monthIndex = this._getMonthIndex(month); - - if (monthIndex === -1) { - return "Invalid month"; - } - + const monthIndex = this._getMonthIndex(Scratch.Cast.toString(args.MONTH)); + if (monthIndex === -1) return "Invalid month"; const date = new Date(year, monthIndex + 1, 0); return date.getDate(); } _getMonthIndex(month) { const months = [ - "January", - "February", - "March", - "April", - "May", - "June", - "July", - "August", - "September", - "October", - "November", - "December", + "January", "February", "March", + "April", "May", "June", + "July", "August", "September", + "October", "November", "December", ]; return months.indexOf(month); } @@ -523,42 +413,25 @@ const dateString = args.TIME ? args.TIME : null; const startDate = new Date(dateString); const difference = this.calculateTimeDifference( - startDate, - endDate, - timeMenu, - false + startDate, endDate, timeMenu, false ); - if (isNaN(difference)) { - return "Invalid Time Input"; - } else { - return difference; - } + if (isNaN(difference)) return "Invalid Time Input"; + else return difference; } countdownBoolean(args) { const endDate = Date.now(); - const dateString = args.TIME ? args.TIME : null; - const startDate = new Date(dateString); - const timeDifference = startDate - endDate; - return timeDifference <= 0; + const startDate = new Date(args.TIME ? args.TIME : null); + return startDate - endDate <= 0; } evaluateTime(args) { - const startTimeString = args.START_TIME ? args.START_TIME : null; - const endTimeString = args.END_TIME ? args.END_TIME : null; - const startDate = new Date(startTimeString); - const endDate = new Date(endTimeString); - - if (isNaN(startDate) || isNaN(endDate)) { - return "Invalid Time Input"; - } - + const startDate = new Date(args.START_TIME ? args.START_TIME : null); + const endDate = new Date(args.END_TIME ? args.END_TIME : null); + if (isNaN(startDate) || isNaN(endDate)) return "Invalid Time Input"; let timeDifference = ""; - if (args.MATH === "add") { - timeDifference = startDate.getTime() + endDate.getTime(); - } else { - timeDifference = startDate.getTime() - endDate.getTime(); - } + if (args.MATH === "add") timeDifference = startDate.getTime() + endDate.getTime(); + else timeDifference = startDate.getTime() - endDate.getTime(); const resultDate = new Date(timeDifference); const year = resultDate.getFullYear(); const month = String(resultDate.getMonth() + 1).padStart(2, "0"); @@ -567,9 +440,7 @@ const hours = String(resultDate.getHours() - changer).padStart(2, "0"); const minutes = String(resultDate.getMinutes()).padStart(2, "0"); const seconds = String(resultDate.getSeconds()).padStart(2, "0"); - - const formattedResult = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; - return formattedResult; + return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; } } Scratch.extensions.register(new Time()); From 80f844338161dbd2bc7ca90a631823bc9228eac7 Mon Sep 17 00:00:00 2001 From: SharkPool <139097378+SharkPool-SP@users.noreply.github.com> Date: Fri, 19 Jan 2024 14:48:44 -0800 Subject: [PATCH 23/30] Update time.js --- extensions/-SIPC-/time.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index 2cd7b7f448..d9b4d430f3 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -77,7 +77,7 @@ { opcode: "calculatetimedurationfromdate", blockType: Scratch.BlockType.REPORTER, - text: "difference between [DATE] to current datetime in [TIME_MENU]", + text: Scratch.translate("difference between [DATE] to current datetime in [TIME_MENU]"), arguments: { DATE: { type: Scratch.ArgumentType.STRING, @@ -92,7 +92,7 @@ { opcode: "calculatetimedurationfromtime", blockType: Scratch.BlockType.REPORTER, - text: "difference between [START_TIME] to current time in [TIME_MENU]", + text: Scratch.translate("difference between [START_TIME] to current time in [TIME_MENU]"), arguments: { START_TIME: { type: Scratch.ArgumentType.STRING, @@ -107,7 +107,7 @@ { opcode: "calculatetimedurationfromstamp", blockType: Scratch.BlockType.REPORTER, - text: "difference between [START_TIME] and [END_TIME] in [TIME_MENU]", + text: Scratch.translate("difference between [START_TIME] and [END_TIME] in [TIME_MENU]"), arguments: { START_TIME: { type: Scratch.ArgumentType.STRING, @@ -126,7 +126,7 @@ { opcode: "calculatetimedifference", blockType: Scratch.BlockType.REPORTER, - text: "difference between [START_TIME] and [END_TIME] in [TIME_MENU]", + text: Scratch.translate("difference between [START_TIME] and [END_TIME] in [TIME_MENU]"), arguments: { START_TIME: { type: Scratch.ArgumentType.STRING, @@ -145,7 +145,7 @@ { opcode: "evaluateTime", blockType: Scratch.BlockType.REPORTER, - text: "[MATH] [START_TIME] and [END_TIME]", + text: Scratch.translate("[MATH] [START_TIME] and [END_TIME]"), arguments: { START_TIME: { type: Scratch.ArgumentType.STRING, @@ -165,7 +165,7 @@ { opcode: "converttotime", blockType: Scratch.BlockType.REPORTER, - text: "convert [VALUE] seconds to [ROUND] time", + text: Scratch.translate("convert [VALUE] seconds to [ROUND] time"), arguments: { VALUE: { type: Scratch.ArgumentType.NUMBER, @@ -180,7 +180,7 @@ { opcode: "convertToValue", blockType: Scratch.BlockType.REPORTER, - text: "convert [VALUE] to [TIME]", + text: Scratch.translate("convert [VALUE] to [TIME]"), arguments: { VALUE: { type: Scratch.ArgumentType.STRING, @@ -195,7 +195,7 @@ { opcode: "daysinmonth", blockType: Scratch.BlockType.REPORTER, - text: "number of days in [MONTH] [YEAR]", + text: Scratch.translate("number of days in [MONTH] [YEAR]"), arguments: { MONTH: { type: Scratch.ArgumentType.STRING, @@ -211,7 +211,7 @@ { opcode: "countdownReport", blockType: Scratch.BlockType.REPORTER, - text: "countdown to [TIME] in [MENU]", + text: Scratch.translate("countdown to [TIME] in [MENU]"), arguments: { TIME: { type: Scratch.ArgumentType.STRING, @@ -226,7 +226,7 @@ { opcode: "countdownBoolean", blockType: Scratch.BlockType.BOOLEAN, - text: "countdown to [TIME] reached?", + text: Scratch.translate("countdown to [TIME] reached?"), arguments: { TIME: { type: Scratch.ArgumentType.STRING, From e2aeb3d6fcf2bebb48929301ab21cb5ef860791b Mon Sep 17 00:00:00 2001 From: Muffin Date: Sat, 27 Jan 2024 22:32:30 -0600 Subject: [PATCH 24/30] Pad time in a way that people are used to reading --- extensions/-SIPC-/time.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index d9b4d430f3..18147aed0e 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -394,9 +394,9 @@ converttotime(args) { const tStamp = args.VALUE ? args.VALUE : 0; - const seconds = args.ROUND === "rounded" ? Math.round(tStamp % 60) : tStamp % 60; - const minutes = Math.round((tStamp / 60) % 60); - const hours = Math.round((tStamp / 3600) % 24); + const seconds = (args.ROUND === "rounded" ? Math.round(tStamp % 60) : tStamp % 60).toString().padStart(2, '0'); + const minutes = Math.round((tStamp / 60) % 60).toString().padStart(2, '0'); + const hours = Math.round((tStamp / 3600) % 24).toString().padStart(2, '0'); return `${hours}:${minutes}:${seconds}`; } From 099de82be3af36473c63a9c3c1845d0d7c4abe79 Mon Sep 17 00:00:00 2001 From: Muffin Date: Sat, 27 Jan 2024 22:32:37 -0600 Subject: [PATCH 25/30] Countdown blocks are redundant --- extensions/-SIPC-/time.js | 45 --------------------------------------- 1 file changed, 45 deletions(-) diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index 18147aed0e..54d5b99d10 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -207,33 +207,6 @@ } }, }, - "---", - { - opcode: "countdownReport", - blockType: Scratch.BlockType.REPORTER, - text: Scratch.translate("countdown to [TIME] in [MENU]"), - arguments: { - TIME: { - type: Scratch.ArgumentType.STRING, - defaultValue: "2007-03-14 09:34:00", - }, - MENU: { - type: Scratch.ArgumentType.STRING, - menu: "Time" - } - }, - }, - { - opcode: "countdownBoolean", - blockType: Scratch.BlockType.BOOLEAN, - text: Scratch.translate("countdown to [TIME] reached?"), - arguments: { - TIME: { - type: Scratch.ArgumentType.STRING, - defaultValue: "2007-03-14 09:34:00" - } - }, - }, ], menus: { Time: { @@ -432,24 +405,6 @@ return months.indexOf(month); } - countdownReport(args) { - const timeMenu = args.MENU; - const endDate = new Date(); - const dateString = args.TIME ? args.TIME : null; - const startDate = new Date(dateString); - const difference = this.calculateTimeDifference( - startDate, endDate, timeMenu, false - ); - if (isNaN(difference)) return "Invalid Time Input"; - else return difference; - } - - countdownBoolean(args) { - const endDate = Date.now(); - const startDate = new Date(args.TIME ? args.TIME : null); - return startDate - endDate <= 0; - } - evaluateTime(args) { const startDate = new Date(args.START_TIME ? args.START_TIME : null); const endDate = new Date(args.END_TIME ? args.END_TIME : null); From 28ed90f5080ffbc9a52e4ee78e81c0769aa4871a Mon Sep 17 00:00:00 2001 From: Muffin Date: Sat, 27 Jan 2024 22:38:23 -0600 Subject: [PATCH 26/30] Refactor days in month --- extensions/-SIPC-/time.js | 78 +++++++++++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 19 deletions(-) diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index 54d5b99d10..6c400fbd5f 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -193,7 +193,7 @@ }, }, { - opcode: "daysinmonth", + opcode: "daysInMonth", blockType: Scratch.BlockType.REPORTER, text: Scratch.translate("number of days in [MONTH] [YEAR]"), arguments: { @@ -249,9 +249,54 @@ Months: { acceptReporters: true, items: [ - "January", "February", "March", "April", - "May", "June", "July", "August", - "September", "October", "November", "December", + { + text: Scratch.translate("January"), + value: "1", + }, + { + text: Scratch.translate("February"), + value: "2" + }, + { + text: Scratch.translate("March"), + value: "3", + }, + { + text: Scratch.translate("April"), + value: "4", + }, + { + text: Scratch.translate("May"), + value: "5", + }, + { + text: Scratch.translate("June"), + value: "6" + }, + { + text: Scratch.translate("July"), + value: "7" + }, + { + text: Scratch.translate("August"), + value: "8" + }, + { + text: Scratch.translate("September"), + value: "9" + }, + { + text: Scratch.translate("October"), + value: "10" + }, + { + text: Scratch.translate("November"), + value: "11" + }, + { + text: Scratch.translate("December"), + value: '12' + } ], }, }, @@ -387,24 +432,19 @@ } } - daysinmonth(args) { - const year = args.YEAR ? args.YEAR : null; - const monthIndex = this._getMonthIndex(Scratch.Cast.toString(args.MONTH)); - if (monthIndex === -1) return "Invalid month"; - const date = new Date(year, monthIndex + 1, 0); + daysInMonth(args) { + const year = Math.round(Scratch.Cast.toNumber(args.YEAR)); + if (year <= 0) { + return 0; + } + const monthIndex = Math.round(Scratch.Cast.toNumber(args.MONTH)); + if (monthIndex < 0 || monthIndex >= 12) { + return 0; + } + const date = new Date(year, monthIndex, 0); return date.getDate(); } - _getMonthIndex(month) { - const months = [ - "January", "February", "March", - "April", "May", "June", - "July", "August", "September", - "October", "November", "December", - ]; - return months.indexOf(month); - } - evaluateTime(args) { const startDate = new Date(args.START_TIME ? args.START_TIME : null); const endDate = new Date(args.END_TIME ? args.END_TIME : null); From 475201440a9314ee9379403f1fea465df6585578 Mon Sep 17 00:00:00 2001 From: Muffin Date: Sat, 27 Jan 2024 23:21:55 -0600 Subject: [PATCH 27/30] remove some blocks that don't make sense, fix a lot of bugs --- extensions/-SIPC-/time.js | 320 ++++++++++++++------------------------ 1 file changed, 113 insertions(+), 207 deletions(-) diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index 6c400fbd5f..470168cea1 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -2,9 +2,11 @@ // ID: sipctime // Description: Blocks for times, dates, and time zones. // By: -SIPC- +// By: SharkPool -// Old Desc: Blocks for interacting with unix timestamps and other date strings. -// Calculation Blocks By: SharkPool +// If you're curious, the default dates are from the first commits of forkphorus & TurboWarp: +// https://github.com/forkphorus/forkphorus/commit/632d3432a8a98abd627b1309f6c85f47dcc6d428 +// https://github.com/TurboWarp/scratch-vm/commit/4a93dab4fa3704ab7a1374b9794026b3330f3433 (function (Scratch) { "use strict"; @@ -15,6 +17,14 @@ const blockIconURI = "data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHdpZHRoPSIxNzUiIGhlaWdodD0iMTc1IiB2aWV3Qm94PSIwLDAsMTc1LDE3NSI+PGcgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTE1Mi41LC05Mi41KSI+PGcgZGF0YS1wYXBlci1kYXRhPSJ7JnF1b3Q7aXNQYWludGluZ0xheWVyJnF1b3Q7OnRydWV9IiBmaWxsPSIjZmZmZmZmIiBmaWxsLXJ1bGU9Im5vbnplcm8iIHN0cm9rZT0ibm9uZSIgc3Ryb2tlLXdpZHRoPSIxIiBzdHJva2UtbGluZWNhcD0iYnV0dCIgc3Ryb2tlLWxpbmVqb2luPSJtaXRlciIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBzdHJva2UtZGFzaGFycmF5PSIiIHN0cm9rZS1kYXNob2Zmc2V0PSIwIiBzdHlsZT0ibWl4LWJsZW5kLW1vZGU6IG5vcm1hbCI+PHBhdGggZD0iTTMyNy41LDE4MGMwLDQ4LjI4MTI1IC0zOS4yMTg3NSw4Ny41IC04Ny41LDg3LjVjLTQ4LjI4MTI1LDAgLTg3LjUsLTM5LjIxODc1IC04Ny41LC04Ny41YzAsLTQ4LjI4MTI1IDM5LjIxODc1LC04Ny41IDg3LjUsLTg3LjVjNDguMjgxMjUsMCA4Ny41LDM5LjIxODc1IDg3LjUsODcuNXpNMjgzLjU5Mzc1LDE5OS42ODc1bC0zNy4zNDM3NSwtMjEuNTYyNXYtNDguMTI1aC0xMi41djU2LjI1aDEuNzE4NzVsNDEuODc1LDI0LjIxODc1eiIvPjwvZz48L2c+PC9zdmc+PCEtLXJvdGF0aW9uQ2VudGVyOjg3LjU6ODcuNS0tPg=="; + const parseDate = str => { + // TODO: support standalone times here, interpret as today + if (!isNaN(str)) { + return new Date(Scratch.Cast.toNumber(str)); + } + return new Date(Scratch.Cast.toString(str)); + }; + class Time { getInfo() { return { @@ -43,7 +53,7 @@ arguments: { timestamp: { type: Scratch.ArgumentType.NUMBER, - defaultValue: "1145141980000" + defaultValue: "1591657163000" }, Timedata: { type: Scratch.ArgumentType.STRING, @@ -54,11 +64,11 @@ { opcode: "TimestampToTime", blockType: Scratch.BlockType.REPORTER, - text: Scratch.translate("convert [timestamp] to datetime"), + text: Scratch.translate("convert [timestamp] to YYYY-MM-DD HH:MM:SS"), arguments: { timestamp: { type: Scratch.ArgumentType.NUMBER, - defaultValue: "1145141980000" + defaultValue: "1591657163000" }, }, }, @@ -69,126 +79,58 @@ arguments: { time: { type: Scratch.ArgumentType.STRING, - defaultValue: "2006-04-16 06:59:40", + defaultValue: "2020-06-08 17:59:23", }, }, }, - { blockType: Scratch.BlockType.LABEL, text: "Time Calculations" }, + '---', { - opcode: "calculatetimedurationfromdate", + opcode: "differenceBetweenDateAndNow", blockType: Scratch.BlockType.REPORTER, - text: Scratch.translate("difference between [DATE] to current datetime in [TIME_MENU]"), + text: Scratch.translate("difference between [DATE] and now in [TIME_MENU]"), arguments: { DATE: { type: Scratch.ArgumentType.STRING, - defaultValue: "2007-03-14 09:34:00" - }, - TIME_MENU: { - type: Scratch.ArgumentType.STRING, - menu: "Time" - } - }, - }, - { - opcode: "calculatetimedurationfromtime", - blockType: Scratch.BlockType.REPORTER, - text: Scratch.translate("difference between [START_TIME] to current time in [TIME_MENU]"), - arguments: { - START_TIME: { - type: Scratch.ArgumentType.STRING, - defaultValue: "00:00:00" - }, - TIME_MENU: { - type: Scratch.ArgumentType.STRING, - menu: "Time" - } - }, - }, - { - opcode: "calculatetimedurationfromstamp", - blockType: Scratch.BlockType.REPORTER, - text: Scratch.translate("difference between [START_TIME] and [END_TIME] in [TIME_MENU]"), - arguments: { - START_TIME: { - type: Scratch.ArgumentType.STRING, - defaultValue: "2007-03-14 09:34:00" - }, - END_TIME: { - type: Scratch.ArgumentType.STRING, - defaultValue: "2016-07-21 15:03:00" + defaultValue: "2020-06-08 17:59:23" }, TIME_MENU: { type: Scratch.ArgumentType.STRING, - menu: "Time" + menu: "DurationUnit" } }, }, { - opcode: "calculatetimedifference", + opcode: "differenceBetweenDates", blockType: Scratch.BlockType.REPORTER, - text: Scratch.translate("difference between [START_TIME] and [END_TIME] in [TIME_MENU]"), + text: Scratch.translate("difference between [START] and [END] in [TIME_MENU]"), arguments: { - START_TIME: { + START: { type: Scratch.ArgumentType.STRING, - defaultValue: "00:00" + defaultValue: "2019-01-04 18:41:04" }, - END_TIME: { + END: { type: Scratch.ArgumentType.STRING, - defaultValue: "00:00" + defaultValue: "2020-06-08 17:59:23" }, TIME_MENU: { type: Scratch.ArgumentType.STRING, - menu: "Time" - } - }, - }, - { - opcode: "evaluateTime", - blockType: Scratch.BlockType.REPORTER, - text: Scratch.translate("[MATH] [START_TIME] and [END_TIME]"), - arguments: { - START_TIME: { - type: Scratch.ArgumentType.STRING, - defaultValue: "2023-10-10 00:00:00" - }, - END_TIME: { - type: Scratch.ArgumentType.STRING, - defaultValue: "1970-01-01 00:10:00" - }, - MATH: { - type: Scratch.ArgumentType.STRING, - menu: "MathType" + menu: "DurationUnit" } }, }, "---", { - opcode: "converttotime", + opcode: "formatTime", blockType: Scratch.BlockType.REPORTER, - text: Scratch.translate("convert [VALUE] seconds to [ROUND] time"), + text: Scratch.translate("format [VALUE] seconds as [ROUND] time"), arguments: { VALUE: { type: Scratch.ArgumentType.NUMBER, - defaultValue: 0 + defaultValue: "3883.2" // no hidden meaning in this one }, ROUND: { type: Scratch.ArgumentType.NUMBER, - menu: "Round" - } - }, - }, - { - opcode: "convertToValue", - blockType: Scratch.BlockType.REPORTER, - text: Scratch.translate("convert [VALUE] to [TIME]"), - arguments: { - VALUE: { - type: Scratch.ArgumentType.STRING, - defaultValue: "1970-01-01 00:00:00" - }, - TIME: { - type: Scratch.ArgumentType.STRING, - menu: "Time" + menu: "TimeFormat" } }, }, @@ -238,13 +180,47 @@ }, ], }, - MathType: { + DurationUnit: { acceptReporters: true, - items: ["add", "subtract"], + items: [ + { + text: Scratch.translate("years"), + value: "years", + }, + { + text: Scratch.translate("months"), + value: "months", + }, + { + text: Scratch.translate("days"), + value: "days", + }, + { + text: Scratch.translate("hours"), + value: "hours", + }, + { + text: Scratch.translate("minutes"), + value: "minutes", + }, + { + text: Scratch.translate("seconds"), + value: "seconds", + }, + ], }, - Round: { + TimeFormat: { acceptReporters: true, - items: ["rounded", "exact"], + items: [ + { + text: Scratch.translate("rounded"), + value: "rounded" + }, + { + text: Scratch.translate("exact"), + value: "exact" + } + ], }, Months: { acceptReporters: true, @@ -302,15 +278,17 @@ }, }; } + Timestamp() { return Date.now(); } + timezone() { return new Date().getTimezoneOffset() / -60; } + Timedata(args) { - args.timestamp = args.timestamp ? args.timestamp : null; - let date1 = new Date(Scratch.Cast.toNumber(args.timestamp)); + const date1 = parseDate(args.timestamp); switch (args.Timedata) { case "year": return date1.getFullYear(); case "month": return date1.getMonth() + 1 < 10 ? "0" + (date1.getMonth() + 1) : date1.getMonth() + 1; @@ -321,117 +299,63 @@ } return 0; } + TimestampToTime({ timestamp }) { timestamp = timestamp ? timestamp : null; - let date2 = new Date(timestamp); - let Y = date2.getFullYear(); - let M = (date2.getMonth() + 1 < 10 ? "0" + (date2.getMonth() + 1) : date2.getMonth() + 1); - let D = (date2.getDate() < 10 ? "0" + date2.getDate() : date2.getDate()); - let h = (date2.getHours() < 10 ? "0" + date2.getHours() : date2.getHours()); - let m = (date2.getMinutes() < 10 ? "0" + date2.getMinutes() : date2.getMinutes()); - let s = date2.getSeconds() < 10 ? "0" + date2.getSeconds() : date2.getSeconds(); + const date = new Date(timestamp); + const Y = date.getFullYear(); + const M = (date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1); + const D = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()); + const h = (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()); + const m = (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()); + const s = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds(); return `${Y}-${M}-${D} ${h}:${m}:${s}`; } + TimeToTimestamp({ time }) { - let data3 = time; - let timestamp = Date.parse(data3); - return timestamp; + const date = new Date(time); + return date.getTime(); } - //SharkPools Section - calculateTimeDifference(startDate, endDate, timeMenu, abs) { - let timeDiff = endDate.getTime() - startDate.getTime(); - timeDiff = abs ? Math.abs(timeDiff) : timeDiff * -1; - switch (timeMenu) { - case "year": return timeDiff / 946080000000; - case "month": return timeDiff / 2592000000; - case "day": return timeDiff / 86400000; - case "hour": return timeDiff / 3600000; - case "minute": return timeDiff / 60000; - case "second": return timeDiff / 1000; - default: return "Invalid Menu Input"; + /** + * @param {Date} startDate + * @param {Date} endDate + * @param {string} timeMenu + * @returns {number} + */ + _calculateTimeDifference(startDate, endDate, timeMenu) { + const timeDiff = endDate.getTime() - startDate.getTime(); + switch (Scratch.Cast.toString(timeMenu)) { + case "years": return timeDiff / (1000 * 60 * 60 * 24 * 365); + case "months": return timeDiff / (1000 * 60 * 60 * 24 * 30.436875); // average month length from https://en.wikipedia.org/wiki/Month + case "days": return timeDiff / (1000 * 60 * 60 * 24); + case "hours": return timeDiff / (1000 * 60 * 60); + case "minutes": return timeDiff / (1000 * 60); + case "seconds": return timeDiff / 1000; + default: return 0; } } - calculatetimedurationfromdate(args) { - const dateString = args.DATE ? args.DATE : null; - const timeMenu = args.TIME_MENU; - const startDate = new Date(dateString); - const endDate = new Date(); - const difference = this.calculateTimeDifference( - startDate, endDate, timeMenu, true - ); - if (isNaN(difference)) return "Invalid Time Input"; - else return difference; + differenceBetweenDateAndNow(args) { + return this._calculateTimeDifference(parseDate(args.DATE), new Date(), args.TIME_MENU); } - calculatetimedurationfromstamp(args) { - const dateString = args.START_TIME ? args.START_TIME : null; - const endDateString = args.END_TIME ? args.END_TIME : null; - const timeMenu = args.TIME_MENU; - const startDate = new Date(dateString); - const endDate = new Date(endDateString); - const difference = this.calculateTimeDifference( - startDate, endDate, timeMenu, true - ); - if (isNaN(difference)) return "Invalid Time Input"; - else return difference; + differenceBetweenDates (args) { + return this._calculateTimeDifference(parseDate(args.START), parseDate(args.END), args.TIME_MENU); } - calculatetimedurationfromtime(args) { - const startTime = args.START_TIME ? args.START_TIME : null; - const timeMenu = args.TIME_MENU; - const [startHour, startMinute] = startTime.split(":"); - const startDate = new Date(); - startDate.setHours(parseInt(startHour), parseInt(startMinute), 0, 0); - const endDate = new Date(); - const difference = this.calculateTimeDifference( - startDate, endDate, timeMenu, true + formatTime(args) { + const totalSeconds = Scratch.Cast.toNumber(args.VALUE); + const seconds = ( + args.ROUND === "rounded" ? + Math.round(totalSeconds % 60).toString().padStart(2, '0') : + (totalSeconds % 60).toFixed(3) ); - if (isNaN(difference)) return "Invalid Time Input"; - else return difference; - } - - calculatetimedifference(args) { - const startTime = args.START_TIME ? args.START_TIME : null; - const endTime = args.END_TIME ? args.END_TIME : null; - const startDate = new Date(); - const endDate = new Date(); - const startHour = parseInt(startTime.split(":")[0]); - const startMinute = parseInt(startTime.split(":")[1]); - const endHour = parseInt(endTime.split(":")[0]); - const endMinute = parseInt(endTime.split(":")[1]); - startDate.setHours(startHour, startMinute, 0, 0); - endDate.setHours(endHour, endMinute, 0, 0); - const difference = this.calculateTimeDifference( - startDate, endDate, args.TIME_MENU, true - ); - if (isNaN(difference)) return "Invalid Time Input"; - else return difference; - } - - converttotime(args) { - const tStamp = args.VALUE ? args.VALUE : 0; - const seconds = (args.ROUND === "rounded" ? Math.round(tStamp % 60) : tStamp % 60).toString().padStart(2, '0'); - const minutes = Math.round((tStamp / 60) % 60).toString().padStart(2, '0'); - const hours = Math.round((tStamp / 3600) % 24).toString().padStart(2, '0'); + const minutes = Math.round((totalSeconds / 60) % 60).toString().padStart(2, '0'); + const hours = Math.round(totalSeconds / 3600).toString().padStart(2, '0'); return `${hours}:${minutes}:${seconds}`; } - convertToValue(args) { - let date = new Date(args.VALUE ? args.VALUE : null); - date = Math.round(date.getTime() / 1000) - 28800; - switch (args.TIME) { - case "year": return date / 31536000; - case "month": return date / 2592000; - case "day": return date / 86400; - case "hour": return date / 3600; - case "minute": return date / 60; - case "second": return date; - default: return "Invalid Menu Input"; - } - } - daysInMonth(args) { const year = Math.round(Scratch.Cast.toNumber(args.YEAR)); if (year <= 0) { @@ -444,24 +368,6 @@ const date = new Date(year, monthIndex, 0); return date.getDate(); } - - evaluateTime(args) { - const startDate = new Date(args.START_TIME ? args.START_TIME : null); - const endDate = new Date(args.END_TIME ? args.END_TIME : null); - if (isNaN(startDate) || isNaN(endDate)) return "Invalid Time Input"; - let timeDifference = ""; - if (args.MATH === "add") timeDifference = startDate.getTime() + endDate.getTime(); - else timeDifference = startDate.getTime() - endDate.getTime(); - const resultDate = new Date(timeDifference); - const year = resultDate.getFullYear(); - const month = String(resultDate.getMonth() + 1).padStart(2, "0"); - const day = String(resultDate.getDate()).padStart(2, "0"); - const changer = args.MATH === "add" ? 8 : -8; - const hours = String(resultDate.getHours() - changer).padStart(2, "0"); - const minutes = String(resultDate.getMinutes()).padStart(2, "0"); - const seconds = String(resultDate.getSeconds()).padStart(2, "0"); - return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; - } } Scratch.extensions.register(new Time()); })(Scratch); From fe80aa9759587bde50e412712846ae7900708252 Mon Sep 17 00:00:00 2001 From: Muffin Date: Sat, 27 Jan 2024 23:22:28 -0600 Subject: [PATCH 28/30] npm run format --- extensions/-SIPC-/time.js | 169 ++++++++++++++++++++++++-------------- 1 file changed, 107 insertions(+), 62 deletions(-) diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index 470168cea1..ac9aa80457 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -17,7 +17,7 @@ const blockIconURI = "data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHdpZHRoPSIxNzUiIGhlaWdodD0iMTc1IiB2aWV3Qm94PSIwLDAsMTc1LDE3NSI+PGcgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTE1Mi41LC05Mi41KSI+PGcgZGF0YS1wYXBlci1kYXRhPSJ7JnF1b3Q7aXNQYWludGluZ0xheWVyJnF1b3Q7OnRydWV9IiBmaWxsPSIjZmZmZmZmIiBmaWxsLXJ1bGU9Im5vbnplcm8iIHN0cm9rZT0ibm9uZSIgc3Ryb2tlLXdpZHRoPSIxIiBzdHJva2UtbGluZWNhcD0iYnV0dCIgc3Ryb2tlLWxpbmVqb2luPSJtaXRlciIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBzdHJva2UtZGFzaGFycmF5PSIiIHN0cm9rZS1kYXNob2Zmc2V0PSIwIiBzdHlsZT0ibWl4LWJsZW5kLW1vZGU6IG5vcm1hbCI+PHBhdGggZD0iTTMyNy41LDE4MGMwLDQ4LjI4MTI1IC0zOS4yMTg3NSw4Ny41IC04Ny41LDg3LjVjLTQ4LjI4MTI1LDAgLTg3LjUsLTM5LjIxODc1IC04Ny41LC04Ny41YzAsLTQ4LjI4MTI1IDM5LjIxODc1LC04Ny41IDg3LjUsLTg3LjVjNDguMjgxMjUsMCA4Ny41LDM5LjIxODc1IDg3LjUsODcuNXpNMjgzLjU5Mzc1LDE5OS42ODc1bC0zNy4zNDM3NSwtMjEuNTYyNXYtNDguMTI1aC0xMi41djU2LjI1aDEuNzE4NzVsNDEuODc1LDI0LjIxODc1eiIvPjwvZz48L2c+PC9zdmc+PCEtLXJvdGF0aW9uQ2VudGVyOjg3LjU6ODcuNS0tPg=="; - const parseDate = str => { + const parseDate = (str) => { // TODO: support standalone times here, interpret as today if (!isNaN(str)) { return new Date(Scratch.Cast.toNumber(str)); @@ -53,22 +53,24 @@ arguments: { timestamp: { type: Scratch.ArgumentType.NUMBER, - defaultValue: "1591657163000" + defaultValue: "1591657163000", }, Timedata: { type: Scratch.ArgumentType.STRING, - menu: "Time" - } + menu: "Time", + }, }, }, { opcode: "TimestampToTime", blockType: Scratch.BlockType.REPORTER, - text: Scratch.translate("convert [timestamp] to YYYY-MM-DD HH:MM:SS"), + text: Scratch.translate( + "convert [timestamp] to YYYY-MM-DD HH:MM:SS" + ), arguments: { timestamp: { type: Scratch.ArgumentType.NUMBER, - defaultValue: "1591657163000" + defaultValue: "1591657163000", }, }, }, @@ -83,39 +85,43 @@ }, }, }, - '---', + "---", { opcode: "differenceBetweenDateAndNow", blockType: Scratch.BlockType.REPORTER, - text: Scratch.translate("difference between [DATE] and now in [TIME_MENU]"), + text: Scratch.translate( + "difference between [DATE] and now in [TIME_MENU]" + ), arguments: { DATE: { type: Scratch.ArgumentType.STRING, - defaultValue: "2020-06-08 17:59:23" + defaultValue: "2020-06-08 17:59:23", }, TIME_MENU: { type: Scratch.ArgumentType.STRING, - menu: "DurationUnit" - } + menu: "DurationUnit", + }, }, }, { opcode: "differenceBetweenDates", blockType: Scratch.BlockType.REPORTER, - text: Scratch.translate("difference between [START] and [END] in [TIME_MENU]"), + text: Scratch.translate( + "difference between [START] and [END] in [TIME_MENU]" + ), arguments: { START: { type: Scratch.ArgumentType.STRING, - defaultValue: "2019-01-04 18:41:04" + defaultValue: "2019-01-04 18:41:04", }, END: { type: Scratch.ArgumentType.STRING, - defaultValue: "2020-06-08 17:59:23" + defaultValue: "2020-06-08 17:59:23", }, TIME_MENU: { type: Scratch.ArgumentType.STRING, - menu: "DurationUnit" - } + menu: "DurationUnit", + }, }, }, "---", @@ -126,12 +132,12 @@ arguments: { VALUE: { type: Scratch.ArgumentType.NUMBER, - defaultValue: "3883.2" // no hidden meaning in this one + defaultValue: "3883.2", // no hidden meaning in this one }, ROUND: { type: Scratch.ArgumentType.NUMBER, - menu: "TimeFormat" - } + menu: "TimeFormat", + }, }, }, { @@ -141,12 +147,12 @@ arguments: { MONTH: { type: Scratch.ArgumentType.STRING, - menu: "Months" + menu: "Months", }, YEAR: { type: Scratch.ArgumentType.NUMBER, - defaultValue: "2000" - } + defaultValue: "2000", + }, }, }, ], @@ -214,12 +220,12 @@ items: [ { text: Scratch.translate("rounded"), - value: "rounded" + value: "rounded", }, { text: Scratch.translate("exact"), - value: "exact" - } + value: "exact", + }, ], }, Months: { @@ -231,7 +237,7 @@ }, { text: Scratch.translate("February"), - value: "2" + value: "2", }, { text: Scratch.translate("March"), @@ -247,32 +253,32 @@ }, { text: Scratch.translate("June"), - value: "6" + value: "6", }, { text: Scratch.translate("July"), - value: "7" + value: "7", }, { text: Scratch.translate("August"), - value: "8" + value: "8", }, { text: Scratch.translate("September"), - value: "9" + value: "9", }, { text: Scratch.translate("October"), - value: "10" + value: "10", }, { text: Scratch.translate("November"), - value: "11" + value: "11", }, { text: Scratch.translate("December"), - value: '12' - } + value: "12", + }, ], }, }, @@ -290,12 +296,26 @@ Timedata(args) { const date1 = parseDate(args.timestamp); switch (args.Timedata) { - case "year": return date1.getFullYear(); - case "month": return date1.getMonth() + 1 < 10 ? "0" + (date1.getMonth() + 1) : date1.getMonth() + 1; - case "day": return date1.getDate() < 10 ? "0" + date1.getDate() : date1.getDate(); - case "hour": return date1.getHours() < 10 ? "0" + date1.getHours() : date1.getHours(); - case "minute": return date1.getMinutes() < 10 ? "0" + date1.getMinutes() : date1.getMinutes(); - case "second": return date1.getSeconds() < 10 ? "0" + date1.getSeconds() : date1.getSeconds(); + case "year": + return date1.getFullYear(); + case "month": + return date1.getMonth() + 1 < 10 + ? "0" + (date1.getMonth() + 1) + : date1.getMonth() + 1; + case "day": + return date1.getDate() < 10 ? "0" + date1.getDate() : date1.getDate(); + case "hour": + return date1.getHours() < 10 + ? "0" + date1.getHours() + : date1.getHours(); + case "minute": + return date1.getMinutes() < 10 + ? "0" + date1.getMinutes() + : date1.getMinutes(); + case "second": + return date1.getSeconds() < 10 + ? "0" + date1.getSeconds() + : date1.getSeconds(); } return 0; } @@ -304,11 +324,16 @@ timestamp = timestamp ? timestamp : null; const date = new Date(timestamp); const Y = date.getFullYear(); - const M = (date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1); - const D = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()); - const h = (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()); - const m = (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()); - const s = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds(); + const M = + date.getMonth() + 1 < 10 + ? "0" + (date.getMonth() + 1) + : date.getMonth() + 1; + const D = date.getDate() < 10 ? "0" + date.getDate() : date.getDate(); + const h = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(); + const m = + date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(); + const s = + date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds(); return `${Y}-${M}-${D} ${h}:${m}:${s}`; } @@ -326,33 +351,53 @@ _calculateTimeDifference(startDate, endDate, timeMenu) { const timeDiff = endDate.getTime() - startDate.getTime(); switch (Scratch.Cast.toString(timeMenu)) { - case "years": return timeDiff / (1000 * 60 * 60 * 24 * 365); - case "months": return timeDiff / (1000 * 60 * 60 * 24 * 30.436875); // average month length from https://en.wikipedia.org/wiki/Month - case "days": return timeDiff / (1000 * 60 * 60 * 24); - case "hours": return timeDiff / (1000 * 60 * 60); - case "minutes": return timeDiff / (1000 * 60); - case "seconds": return timeDiff / 1000; - default: return 0; + case "years": + return timeDiff / (1000 * 60 * 60 * 24 * 365); + case "months": + return timeDiff / (1000 * 60 * 60 * 24 * 30.436875); // average month length from https://en.wikipedia.org/wiki/Month + case "days": + return timeDiff / (1000 * 60 * 60 * 24); + case "hours": + return timeDiff / (1000 * 60 * 60); + case "minutes": + return timeDiff / (1000 * 60); + case "seconds": + return timeDiff / 1000; + default: + return 0; } } differenceBetweenDateAndNow(args) { - return this._calculateTimeDifference(parseDate(args.DATE), new Date(), args.TIME_MENU); + return this._calculateTimeDifference( + parseDate(args.DATE), + new Date(), + args.TIME_MENU + ); } - differenceBetweenDates (args) { - return this._calculateTimeDifference(parseDate(args.START), parseDate(args.END), args.TIME_MENU); + differenceBetweenDates(args) { + return this._calculateTimeDifference( + parseDate(args.START), + parseDate(args.END), + args.TIME_MENU + ); } formatTime(args) { const totalSeconds = Scratch.Cast.toNumber(args.VALUE); - const seconds = ( - args.ROUND === "rounded" ? - Math.round(totalSeconds % 60).toString().padStart(2, '0') : - (totalSeconds % 60).toFixed(3) - ); - const minutes = Math.round((totalSeconds / 60) % 60).toString().padStart(2, '0'); - const hours = Math.round(totalSeconds / 3600).toString().padStart(2, '0'); + const seconds = + args.ROUND === "rounded" + ? Math.round(totalSeconds % 60) + .toString() + .padStart(2, "0") + : (totalSeconds % 60).toFixed(3); + const minutes = Math.round((totalSeconds / 60) % 60) + .toString() + .padStart(2, "0"); + const hours = Math.round(totalSeconds / 3600) + .toString() + .padStart(2, "0"); return `${hours}:${minutes}:${seconds}`; } From 8fadbe524813a6534c6ddd0743c5ed4015825a1a Mon Sep 17 00:00:00 2001 From: Muffin Date: Sat, 27 Jan 2024 23:27:34 -0600 Subject: [PATCH 29/30] Make a new block instead if you dont like that --- extensions/-SIPC-/time.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index ac9aa80457..05472818d9 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -290,7 +290,7 @@ } timezone() { - return new Date().getTimezoneOffset() / -60; + return "UTC+" + new Date().getTimezoneOffset() / -60; } Timedata(args) { From c46bb214c420fd69584f02642f410b925b30460e Mon Sep 17 00:00:00 2001 From: Muffin Date: Sat, 27 Jan 2024 23:28:37 -0600 Subject: [PATCH 30/30] use parseDate() everywhere --- extensions/-SIPC-/time.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index 05472818d9..e789b517b2 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -321,8 +321,7 @@ } TimestampToTime({ timestamp }) { - timestamp = timestamp ? timestamp : null; - const date = new Date(timestamp); + const date = parseDate(timestamp); const Y = date.getFullYear(); const M = date.getMonth() + 1 < 10 @@ -338,8 +337,7 @@ } TimeToTimestamp({ time }) { - const date = new Date(time); - return date.getTime(); + return parseDate(time).getTime(); } /**