Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // You would need to send a json formated timeRequest Object:
- @serializable
- class timeRequest {
- /**
- * A Unix timestamp in ms of the time that shall be converted.
- * For the current time you can use `Date.now();`
- */
- timestamp: i64 /*ms*/ = 0;
- /**
- * There are several supported formats but only the `json` format can be parsed as a PITDate object.
- * Other supported formats are:
- * Currently only 24h format is supported!
- *
- * "iso" : 2025-02-29T15:37
- * "date" : 2025-02-29
- * "dd.mm.yyyy" : 29.02.2025
- * "mm.dd.yyyy" : 02.29.2025
- * "dd.mm.yyyy hh:mm" : 29.02.2025 15:37
- * "mm.dd.yyyy hh:mm" : 02.29.2025 15:37
- * "longdate" : 29. February 2025
- * "longdate3" : 29. Feb. 2025
- * "longus" : February 29, 2025
- * "longus3" : Feb. 29, 2025
- * "longdatetime" : 29. February 2025 15:37
- * "longdatetime3" : 29. Feb. 2025 15:37
- * "longustime" : February 29, 2025 15:37
- * "longustime3" : Feb. 29, 2025 15:37
- * "compact" : 202502291537
- * "json" : JSON fromated PITDate Object
- * "full" : 2025-02-29 15:37
- *
- * @property {string} format
- */
- format: string = 'json';
- /**
- * The type of leap year fix.
- *
- * This can be either `patched` or `aligned`.
- * "date" : 2025-02-29
- * **patched**
- * Means that there will be 1 extra day in February each leap year which will cause an offset of 4h (in PIT 1h = 50min)
- * This will be fixed by adding another leap day every 5th year. (so 2 extra days in Feb).
- *
- * **aligned**
- * This will also add a leapday every leap year but to avoid the offsetthe leapday will be 4 PIT hours longer.
- * When using this time please refer to it as Phantom Isles Aligned Time (PIAT).
- *
- * @property {string} type
- */
- type: string = 'patched';
- }
- /* together with the `getTime` topic.
- You will then recieve a JSON-formated `PITDate` object: */
- @serializable
- class PITDate {
- /** Year (i16) */
- year: i16 = 1970;
- /** Month (i8; 1-12) */
- month: i8 = 1;
- /** Day (i8; 1-based) */
- day: i8 = 1;
- /** Hour (i8; 0-based) */
- hour: i8 = 0;
- /** Minute (i8; 0-based) */
- minute: i8 = 0;
- /** Original unix timestamp (i64, ms) */
- timestamp: i64 = 0;
- }
- /* Example: */
- const PIT_SCRIPT = 'PITScriptAdress'; /*Contact me if you want to use it.*/
- function getPITTime(time: i64): PITDate|false {
- /* !!!! To check if this is even used and how frequently I DO log requests and their scripts adresses. !!!! */
- const req = Script.request(script,'getTime', `{"timestamp": ${now}, 'format': 'json', 'type': 'patched'}`);
- if (req.is_error) {/* Do your Error handling here.*/ return false;} else {
- return JSON.parse<PITDate>(req);
- }
- }
- const now = Date.now();
- const PIT = getPITTime(now);
- /*Now do whatever you want with that time. ^w^*/
- /*Signed: Felinex Gloomfort*/
Advertisement
Add Comment
Please, Sign In to add comment