From 32ec50906489b9e1bfc3845e776e52a2d4016ea8 Mon Sep 17 00:00:00 2001 From: Fenris Wolf Date: Thu, 26 Sep 2024 16:47:19 +0200 Subject: [PATCH] [upd] plankton --- lib/plankton/plankton.d.ts | 408 +++----------- lib/plankton/plankton.js | 1090 ++++++++++-------------------------- tools/update-plankton | 1 + 3 files changed, 350 insertions(+), 1149 deletions(-) diff --git a/lib/plankton/plankton.d.ts b/lib/plankton/plankton.d.ts index 940f9a2..3248bb2 100644 --- a/lib/plankton/plankton.d.ts +++ b/lib/plankton/plankton.d.ts @@ -6,29 +6,6 @@ type int = number; * @author fenris */ type float = number; -/** - * @author fenris - */ -type type_date = { - year: int; - month: int; - day: int; -}; -/** - * @author fenris - */ -type type_time = { - hour: int; - minute: int; - second: int; -}; -/** - * @author fenris - */ -type type_datetimeobject = { - date: type_date; - time: type_time; -}; declare var process: any; declare var require: any; declare class Buffer { @@ -2942,38 +2919,15 @@ declare namespace lib_plankton.session { clear?: boolean; }): Promise; } -declare module lib_et { +declare namespace lib_plankton.pit { /** - * @desc type of extended timestamp - * @author fenris */ - type type_et = { - era: int; - stamp: int; - }; - /** - * @desc type of UNIX timestamp - * @author fenris - */ - type type_timestamp = int; - /** - * @desc type of Javascript Date object - * @author fenris - */ - type type_jsdate = Date; - /** - * @author fenris - */ - type type_components = { + type type_date = { year: int; month: int; day: int; - hour: int; - minute: int; - second: int; }; /** - * @author fenris */ type type_ywd = { year: int; @@ -2981,310 +2935,78 @@ declare module lib_et { day: int; }; /** - * @author fenris */ - function part(et1: type_et, et2: type_et): type_et; - /** - * @desc less - * @author fenris - */ - function before(reference: type_et, et: type_et): boolean; - /** - * @desc greater - * @author fenris - */ - function after(reference: type_et, et: type_et): boolean; - /** - * @author fenris - */ - function between(begin: type_et, end: type_et, et: type_et): boolean; - /** - * @author fenris - */ - function intersect(begin1: type_et, end1: type_et, begin2: type_et, end2: type_et): boolean; - /** - * @author fenris - */ - function move(base: type_et, span: type_et): type_et; - /** - * @desc currified version of "move" - * @author fenris - */ - function move_(span: type_et): (base: type_et) => type_et; - /** - * @author fenris - */ - function from_timestamp(timestamp: type_timestamp): type_et; - /** - * @author fenris - */ - function to_timestamp(et: type_et): type_timestamp; - /** - * @author fenris - */ - function from_jsdate(jsdate: type_jsdate): type_et; - /** - * @author fenris - */ - function to_jsdate(et: type_et): type_jsdate; - /** - * @author fenris - */ - function from_components(components: type_components): type_et; - /** - * @author fenris - */ - function to_components(et: type_et): type_components; - /** - * @author fenris - */ - function now(): type_et; - /** - * @author fenris - */ - function to_string(et: type_et): string; - /** - * @author fenris - */ - function to_string_ywd(et: type_et): string; - /** - * @desc retrieve week of year - * @author fenris - */ - function get_woy(et: type_et): int; - /** - * @desc retrieve day of week - * @author fenris - */ - function get_dow(et: type_et): int; - /** - * @author fenris - */ - function trunc_minute(et?: type_et): type_et; - /** - * @author fenris - */ - function trunc_hour(et?: type_et): type_et; - /** - * @author fenris - */ - function trunc_day(et?: type_et): type_et; - /** - * @author fenris - */ - function trunc_month(et?: type_et): type_et; - /** - * @author fenris - */ - function trunc_year(et?: type_et): type_et; - /** - * @author fenris - */ - function trunc_week(et?: type_et): type_et; - /** - * @author fenris - */ - function span_second(seconds?: int): type_et; - /** - * @author fenris - */ - function span_minute(minutes?: int): type_et; - /** - * @author fenris - */ - function span_hour(hours?: int): type_et; - /** - * @author fenris - */ - function span_day(days?: int): type_et; - /** - * @author fenris - */ - function span_week(weeks?: int): type_et; - /** - * @author fenris - */ - function span_year(years?: int): type_et; -} -declare module lib_et { - /** - * @author fenris - */ - class class_et { - /** - * @author fenris - */ - protected subject: type_et; - /** - * @author fenris - */ - constructor(subject: type_et); - /** - * @author fenris - */ - move(et: class_et): class_et; - /** - * @author fenris - */ - before(et: class_et): boolean; - /** - * @author fenris - */ - after(et: class_et): boolean; - /** - * @author fenris - */ - between(et1: class_et, et2: class_et): boolean; - /** - * @author fenris - */ - trunc_minute(): class_et; - /** - * @author fenris - */ - trunc_hour(): class_et; - /** - * @author fenris - */ - trunc_day(): class_et; - /** - * @author fenris - */ - trunc_month(): class_et; - /** - * @author fenris - */ - trunc_year(): class_et; - /** - * @author fenris - */ - trunc_week(): class_et; - /** - * @author fenris - */ - static now(): class_et; - /** - * @author fenris - */ - static span_second(count?: int): class_et; - /** - * @author fenris - */ - static span_minute(count?: int): class_et; - /** - * @author fenris - */ - static span_hour(count?: int): class_et; - /** - * @author fenris - */ - static span_day(count?: int): class_et; - /** - * @author fenris - */ - static span_week(count?: int): class_et; - /** - * @author fenris - */ - static span_year(count?: int): class_et; - /** - * @author fenris - */ - static from_timestamp(timestamp: type_timestamp): class_et; - /** - * @author fenris - */ - to_timestamp(): type_timestamp; - /** - * @author fenris - */ - static from_jsdate(jsdate: type_jsdate): class_et; - /** - * @author fenris - */ - to_jsdate(): type_jsdate; - /** - * @author fenris - */ - static from_components(components: type_components): class_et; - /** - * @author fenris - */ - to_components(): type_components; - /** - * @author fenris - */ - get_woy(): int; - /** - * @author fenris - */ - get_dow(): int; - /** - * @author fenris - */ - to_string(): string; - } -} -declare var global_config: any; -/** - * @author neuc - */ -declare namespace lib_plankton.date { - /** - * @author neu3no, fenris - */ - function set_days(day_names: Array): void; - /** - * @author neu3no, fenris - */ - function set_months(month_names: Array): void; - /** - * @desc week of year - * @param {Date} date - * @return {int} - * @author fenris - */ - function get_week(date: Date): int; - /** - * @author neu3no, fenris - */ - function set_currentDate(date: Date): void; - /** - * @author neu3no, fenris - */ - function parse(format: string, date?: Date): string; - /** - * @author neu3no, fenris - */ - function locale_date(date?: Date, ignore_error?: boolean): string; - /** - */ - type type_unixtimestamp = int; - /** - */ - type type_components = { - timezone_offset: int; - year: int; - month: int; - day: int; + type type_time = { hour: int; minute: int; second: int; }; /** */ - function now(): type_unixtimestamp; + type type_datetime = { + timezone_shift: int; + date: type_date; + time: (null | type_time); + }; /** */ - function from_components(components: type_components): type_unixtimestamp; - /** - */ - function to_components(unixtimestamp: type_unixtimestamp): type_components; - /** - */ - function get_timestamp_from_year_and_week_and_day(year: int, week: int, day: int): type_unixtimestamp; + type type_pit = int; +} +declare namespace lib_plankton.pit { + /** + */ + function date_object_get_week_of_year(date: Date): int; + /** + */ + function to_unix_timestamp(pit: type_pit): int; + /** + */ + function from_unix_timestamp(unix_timestamp: int): type_pit; + /** + */ + function to_date_object(pit: type_pit): Date; + /** + * @todo timezone + */ + function to_datetime(pit: type_pit, options?: { + timezone_shift?: int; + }): type_datetime; + /** + */ + function from_datetime(datetime: type_datetime): type_pit; + /** + */ + function is_before(pit: type_pit, reference: type_pit): boolean; + /** + */ + function is_between(pit: type_pit, reference_left: type_pit, reference_right: type_pit): boolean; + /** + */ + function shift_day(pit: type_pit, increment: int): type_pit; + /** + */ + function shift_week(pit: type_pit, increment: int): type_pit; + /** + */ + function trunc_week(pit: type_pit): type_pit; + /** + */ + function now(): type_pit; + /** + * @param year year according to specified timezone shift + * @param week week according to specified timezone shift + * @return the begin of the week (monday, 00:00) + */ + function from_ywd(ywd: type_ywd, options?: { + timezone_shift?: int; + }): type_pit; + /** + * @todo timezone + */ + function to_ywd(pit: type_pit, options?: { + timezone_shift?: int; + }): type_ywd; } -declare var strftime: typeof lib_plankton.date; declare namespace lib_plankton.ical { /** */ @@ -3436,7 +3158,7 @@ declare namespace lib_plankton.ical { declare namespace lib_plankton.ical { /** */ - function datetime_to_unixtimestamp(datetime: type_datetime): lib_plankton.date.type_unixtimestamp; + function datetime_to_unixtimestamp(datetime: type_datetime): int; /** * @see https://www.rfc-editor.org/rfc/rfc5545 * @see https://icalendar.org/iCalendar-RFC-5545/ diff --git a/lib/plankton/plankton.js b/lib/plankton/plankton.js index 953ff63..b588354 100644 --- a/lib/plankton/plankton.js +++ b/lib/plankton/plankton.js @@ -10098,721 +10098,60 @@ var lib_plankton; })(session = lib_plankton.session || (lib_plankton.session = {})); })(lib_plankton || (lib_plankton = {})); /* -This file is part of »bacterio-plankton:date«. +This file is part of »bacterio-plankton:pit«. Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' -»bacterio-plankton:date« is free software: you can redistribute it and/or modify +»bacterio-plankton:pit« is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. -»bacterio-plankton:date« is distributed in the hope that it will be useful, +»bacterio-plankton:pit« is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:date«. If not, see . +along with »bacterio-plankton:pit«. If not, see . */ -var lib_et; -(function (lib_et) { - /** - * @author fenris - */ - function div(x, y) { - return Math.floor(x / y); - } - /** - * @author fenris - */ - function mod(x, y) { - return (x - (y * div(x, y))); - } - /** - * @author fenris - */ - function json_encode(obj) { - return JSON.stringify(obj); - } - /** - * @desc the maximum of a regular UNIX-timestamp: 2^31-1; one second is cut - * @author fenris - */ - const _modulus = 0x7FFFFFFF; - /** - * @desc add (e1,s1) (e2,s2) = (e1+e2+((s1+s2) div m),(s1+s2) mod m) - * @author fenris - */ - function add(et1, et2) { - let era = (et1.era + et2.era + div(et1.stamp + et2.stamp, _modulus)); - let stamp = mod(et1.stamp + et2.stamp, _modulus); - return { "era": era, "stamp": stamp }; - } - /** - * @desc neutral = (0,0) - */ - function neutral() { - return { "era": 0, "stamp": 0 }; - } - /** - * @desc invert (e,s) = (-1-e,m-s) - */ - function invert(et) { - let era = (-1 - et.era); - let stamp = (_modulus - et.stamp); - return { "era": era, "stamp": stamp }; - } - /** - * @author fenris - */ - function part(et1, et2) { - return add(et1, invert(et2)); - } - lib_et.part = part; - /** - * @desc less - * @author fenris - */ - function before(reference, et) { - let et_ = part(et, reference); - return ((et_.era >= 0) && (et_.stamp > 0)); - } - lib_et.before = before; - /** - * @desc greater - * @author fenris - */ - function after(reference, et) { - let et_ = part(reference, et); - return ((et_.era >= 0) && (et_.stamp > 0)); - } - lib_et.after = after; - /** - * @author fenris - */ - function between(begin, end, et) { - return (before(begin, et) - && - after(end, et)); - } - lib_et.between = between; - /** - * @author fenris - */ - function intersect(begin1, end1, begin2, end2) { - return ((between(begin1, end1, begin2) - || - between(begin1, end1, end2)) - || - (between(begin2, end2, begin1) - || - between(begin2, end2, end1))); - } - lib_et.intersect = intersect; - /** - * @author fenris - */ - function move(base, span) { - return add(base, span); - } - lib_et.move = move; - /** - * @desc currified version of "move" - * @author fenris - */ - function move_(span) { - return (base => move(base, span)); - } - lib_et.move_ = move_; - /** - * @author fenris - */ - function from_timestamp(timestamp) { - let era = div(timestamp, _modulus); - let stamp = mod(timestamp, _modulus); - let et = { "era": era, "stamp": stamp }; - return et; - } - lib_et.from_timestamp = from_timestamp; - /** - * @author fenris - */ - function to_timestamp(et) { - if (et.era != 0) { - const message = "case (era <> 0) not properly implemented"; - console.warn(message + "; well ... i'll do my very best ..."); - // throw (new Error(message)); - } - let timestamp = ((et.era * _modulus) + et.stamp); - return timestamp; - } - lib_et.to_timestamp = to_timestamp; - /** - * @author fenris - */ - function from_jsdate(jsdate) { - const timestamp = Math.floor(jsdate.getTime() / 1000); - const et = from_timestamp(timestamp); - return et; - } - lib_et.from_jsdate = from_jsdate; - /** - * @author fenris - */ - function to_jsdate(et) { - const timestamp = to_timestamp(et); - const jsdate = (new Date(timestamp * 1000)); - return jsdate; - } - lib_et.to_jsdate = to_jsdate; - /** - * @author fenris - */ - function from_components(components) { - const timestamp = Math.floor(Date.UTC((components.year), (components.month - 1), (components.day), (components.hour || 0), (components.minute || 0), (components.second || 0)) - / - 1000); - const et = from_timestamp(timestamp); - return et; - } - lib_et.from_components = from_components; - /** - * @author fenris - */ - function to_components(et) { - const jsdate = to_jsdate(et); - const components = { - "year": jsdate.getUTCFullYear(), - "month": jsdate.getUTCMonth() + 1, - "day": jsdate.getUTCDate(), - "hour": jsdate.getUTCHours(), - "minute": jsdate.getUTCMinutes(), - "second": jsdate.getUTCSeconds(), - }; - return components; - } - lib_et.to_components = to_components; - /** - * @author fenris - */ - function now() { - let timestamp = Math.floor(Date.now() / 1000); - let et = from_timestamp(timestamp); - return et; - } - lib_et.now = now; - /** - * @author fenris - */ - function to_string(et) { - // return (json_encode(et) + " ~ " + json_encode(to_components(et))); - return to_jsdate(et).toUTCString(); - } - lib_et.to_string = to_string; - /** - * @author fenris - */ - function to_string_ywd(et) { - // return (json_encode(et) + " ~ " + json_encode(to_components(et))); - return to_jsdate(et).toUTCString(); - } - lib_et.to_string_ywd = to_string_ywd; - /** - * @desc retrieve week of year - * @author fenris - */ - function get_woy(et) { - let jsdate = to_jsdate(et); - let begin_of_year = new Date(jsdate.getFullYear(), 0, 1, 12, 0, 0); - let day_of_week = begin_of_year.getDay(); - let overhang = (day_of_week >= 4); - let factor = (1000 * 60 * 60 * 24); - let days = ((jsdate.getTime() - begin_of_year.getTime()) / factor); - let week = (Math.ceil((days + day_of_week) / 7) - (overhang ? 1 : 0)); - return week; - } - lib_et.get_woy = get_woy; - /** - * @desc retrieve day of week - * @author fenris - */ - function get_dow(et) { - let jsdate = to_jsdate(et); - let dow = (mod(jsdate.getDay() - 1, 7) + 1); - return dow; - } - lib_et.get_dow = get_dow; - /** - * @author fenris - */ - function trunc_minute(et = now()) { - let components = to_components(et); - let components_ = { - "year": components.year, - "month": components.month, - "day": components.day, - "hour": components.hour, - "minute": components.minute, - "second": 0 - }; - let et_ = from_components(components_); - return et_; - } - lib_et.trunc_minute = trunc_minute; - /** - * @author fenris - */ - function trunc_hour(et = now()) { - let components = to_components(et); - let components_ = { - "year": components.year, - "month": components.month, - "day": components.day, - "hour": components.hour, - "minute": 0, - "second": 0 - }; - let et_ = from_components(components_); - return et_; - } - lib_et.trunc_hour = trunc_hour; - /** - * @author fenris - */ - function trunc_day(et = now()) { - let components = to_components(et); - let components_ = { - "year": components.year, - "month": components.month, - "day": components.day, - "hour": 0, - "minute": 0, - "second": 0 - }; - let et_ = from_components(components_); - return et_; - } - lib_et.trunc_day = trunc_day; - /** - * @author fenris - */ - function trunc_month(et = now()) { - let components = to_components(et); - let components_ = { - "year": components.year, - "month": components.month, - "day": 0, - "hour": 0, - "minute": 0, - "second": 0 - }; - let et_ = from_components(components_); - return et_; - } - lib_et.trunc_month = trunc_month; - /** - * @author fenris - */ - function trunc_year(et = now()) { - let components = to_components(et); - let components_ = { - "year": components.year, - "month": 0, - "day": 0, - "hour": 0, - "minute": 0, - "second": 0 - }; - let et_ = from_components(components_); - return et_; - } - lib_et.trunc_year = trunc_year; - /** - * @author fenris - */ - function trunc_week(et = now()) { - let et_ = trunc_day(et); - while (to_jsdate(et_).getDay() > 1) { - et_ = add(et_, span_day(-1)); - } - return et_; - } - lib_et.trunc_week = trunc_week; - /** - * @author fenris - */ - function span_second(seconds = 1) { - return from_timestamp(seconds); - } - lib_et.span_second = span_second; - /** - * @author fenris - */ - function span_minute(minutes = 1) { - return span_second(minutes * 60); - } - lib_et.span_minute = span_minute; - /** - * @author fenris - */ - function span_hour(hours = 1) { - return span_minute(hours * 60); - } - lib_et.span_hour = span_hour; - /** - * @author fenris - */ - function span_day(days = 1) { - return span_hour(days * 24); - } - lib_et.span_day = span_day; - /** - * @author fenris - */ - function span_week(weeks = 1) { - return span_day(weeks * 7); - } - lib_et.span_week = span_week; - /** - * @author fenris - */ - function span_year(years = 1) { - return span_second(Math.floor(years * 365.25 * 24 * 60 * 60)); - } - lib_et.span_year = span_year; -})(lib_et || (lib_et = {})); /* -This file is part of »bacterio-plankton:date«. +This file is part of »bacterio-plankton:pit«. Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' -»bacterio-plankton:date« is free software: you can redistribute it and/or modify +»bacterio-plankton:pit« is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. -»bacterio-plankton:date« is distributed in the hope that it will be useful, +»bacterio-plankton:pit« is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:date«. If not, see . - */ -var lib_et; -(function (lib_et) { - /** - * @author fenris - */ - class class_et { - /** - * @author fenris - */ - constructor(subject) { - this.subject = subject; - } - /** - * @author fenris - */ - move(et) { - return (new class_et(lib_et.move(this.subject, et.subject))); - } - /** - * @author fenris - */ - before(et) { - return lib_et.before(et.subject, this.subject); - } - /** - * @author fenris - */ - after(et) { - return lib_et.after(et.subject, this.subject); - } - /** - * @author fenris - */ - between(et1, et2) { - return lib_et.between(et1.subject, et2.subject, this.subject); - } - /** - * @author fenris - */ - trunc_minute() { - return (new class_et(lib_et.trunc_minute(this.subject))); - } - /** - * @author fenris - */ - trunc_hour() { - return (new class_et(lib_et.trunc_hour(this.subject))); - } - /** - * @author fenris - */ - trunc_day() { - return (new class_et(lib_et.trunc_day(this.subject))); - } - /** - * @author fenris - */ - trunc_month() { - return (new class_et(lib_et.trunc_month(this.subject))); - } - /** - * @author fenris - */ - trunc_year() { - return (new class_et(lib_et.trunc_year(this.subject))); - } - /** - * @author fenris - */ - trunc_week() { - return (new class_et(lib_et.trunc_week(this.subject))); - } - /** - * @author fenris - */ - static now() { - return (new class_et(lib_et.now())); - } - /** - * @author fenris - */ - static span_second(count = 1) { - return (new class_et(lib_et.span_second(count))); - } - /** - * @author fenris - */ - static span_minute(count = 1) { - return (new class_et(lib_et.span_minute(count))); - } - /** - * @author fenris - */ - static span_hour(count = 1) { - return (new class_et(lib_et.span_hour(count))); - } - /** - * @author fenris - */ - static span_day(count = 1) { - return (new class_et(lib_et.span_day(count))); - } - /** - * @author fenris - */ - static span_week(count = 1) { - return (new class_et(lib_et.span_week(count))); - } - /** - * @author fenris - */ - static span_year(count = 1) { - return (new class_et(lib_et.span_year(count))); - } - /** - * @author fenris - */ - static from_timestamp(timestamp) { - return (new class_et(lib_et.from_timestamp(timestamp))); - } - /** - * @author fenris - */ - to_timestamp() { - return lib_et.to_timestamp(this.subject); - } - /** - * @author fenris - */ - static from_jsdate(jsdate) { - return (new class_et(lib_et.from_jsdate(jsdate))); - } - /** - * @author fenris - */ - to_jsdate() { - return lib_et.to_jsdate(this.subject); - } - /** - * @author fenris - */ - static from_components(components) { - return (new class_et(lib_et.from_components(components))); - } - /** - * @author fenris - */ - to_components() { - return lib_et.to_components(this.subject); - } - /** - * @author fenris - */ - get_woy() { - return lib_et.get_woy(this.subject); - } - /** - * @author fenris - */ - get_dow() { - return lib_et.get_dow(this.subject); - } - /** - * @author fenris - */ - to_string() { - return lib_et.to_string(this.subject); - } - } - lib_et.class_et = class_et; -})(lib_et || (lib_et = {})); -/* -This file is part of »bacterio-plankton:date«. - -Copyright 2016-2024 'Christian Fraß, Christian Neubauer, Martin Springwald GbR' - - -»bacterio-plankton:date« is free software: you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -»bacterio-plankton:date« is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with »bacterio-plankton:date«. If not, see . - */ -/** - * @author neuc +along with »bacterio-plankton:pit«. If not, see . */ var lib_plankton; (function (lib_plankton) { - var date; - (function (date_1) { + var pit; + (function (pit_1) { /** - * @author neu3no, fenris */ - var _days = [ - "Sunday", - "Monday", - "Tuesday", - "Wednesday", - "Thursday", - "Friday", - "Saturday" - ]; - /** - * @author neu3no, fenris - */ - var _months = [ - "January", - "February", - "March", - "April", - "May", - "June", - "July", - "August", - "September", - "October", - "November", - "December" - ]; - /** - * @author neu3no, fenris - */ - var _segments = { - "%a": (date => _days[date.getDay()].slice(0, 3)), - "%A": (date => _days[date.getDay()]), - "%b": (date => _days[date.getMonth()].slice(0, 3)), - "%B": (date => _days[date.getMonth()]), - "%c": (date => date.toLocaleString()), - "%C": (date => Math.floor((date.getFullYear()) / 100).toString()), - "%d": (date => lib_plankton.string.sprintf("%02d", [date.getDate()])), - "%D": (date => parse("%m/%d/%y", date)), - "%e": (date => lib_plankton.string.sprintf("%2d", [date.getDate()])), - "%F": (date => parse("%Y-%m-%d", date)), - "%g": (date => lib_plankton.string.sprintf("%02d", [date.getFullYear() % 1000])), - "%G": (date => date.getFullYear().toString()), - "%h": (date => parse("%b", date)), - "%H": (date => lib_plankton.string.sprintf("%02d", [date.getHours()])), - "%I": (date => lib_plankton.string.sprintf("%02d", [((date.getHours() > 12) ? (date.getHours() - 12) : date.getHours())])), - "%j": (date => lib_plankton.string.sprintf("%03d", [helper_dayOfYear(date)])), - "%m": (date => lib_plankton.string.sprintf("%02d", [date.getMonth() + 1])), - "%M": (date => lib_plankton.string.sprintf("%02d", [date.getMinutes()])), - "%n": (date => "\n"), - "%p": (date => ((date.getHours() > 12) ? "PM" : "AM")), - "%r": (date => parse("%I:%M:%S %p", date)), - "%R": (date => parse("%H:%M", date)), - "%S": (date => date.getSeconds().toString()), - "%t": (date => "\t"), - "%T": (date => parse("%H:%M:%S", date)), - "%u": (date => lib_plankton.string.sprintf("%02d", [((date.getDay() === 0) ? 7 : date.getDay())])), - "%U": (date => lib_plankton.string.sprintf("%02d", [helper_englishWeekOfYear(date)])), - "%V": (date => lib_plankton.string.sprintf("%02d", [helper_weekOfYear(date)])), - "%w": (date => lib_plankton.string.sprintf("%02d", [date.getDay().toString()])), - "%W": (date => parse("%w", date)), - "%x": (date => parse("%m/%d/%G", date)), - "%X": (date => parse("%T", date)), - "%y": (date => parse("%g", date)), - "%Y": (date => parse("%G", date)), - "%z": (date => date.getTimezoneOffset().toString()), - "%Z": (date => date.toUTCString().split(' ').pop()), - "%%": (date => "%"), - }; - /** - * @author neu3no, fenris - */ - var _currentDate = (new Date(Date.now())); - /** - * @author neu3no, fenris - */ - function set_days(day_names) { - _days = day_names; - } - date_1.set_days = set_days; - /** - * @author neu3no, fenris - */ - function set_months(month_names) { - _months = month_names; - } - date_1.set_months = set_months; - /** - * @desc source: https://stackoverflow.com/questions/8619879/javascript-calculate-the-day-of-the-year-1-366 - * @author neu3no, fenris - */ - function helper_dayOfYear(date) { - let start = new Date(date.getFullYear(), 0, 0); - let diff = (date.getTime() - start.getTime()); - let oneDay = (1000 * 60 * 60 * 24); - return Math.floor(diff / oneDay); - } - /** - * @desc source: http://weeknumber.net/how-to/javascript - * @author neu3no, fenris - */ - function helper_weekOfYear(date_) { - let date = new Date(date_.getTime()); - date.setHours(0, 0, 0, 0); + function date_object_get_week_of_year(date) { + let date_ = new Date(date.getTime()); + date_.setHours(0, 0, 0, 0); // Thursday in current week decides the year. - date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7); + date_.setDate(date_.getDate() + 3 - (date_.getDay() + 6) % 7); // January 4 is always in week 1. - let week1 = new Date(date.getFullYear(), 0, 4); + let week1 = new Date(date_.getFullYear(), 0, 4); // Adjust to Thursday in week 1 and count number of weeks from date to week1. return (1 + - Math.round((((date.getTime() - week1.getTime()) / 86400000) + Math.round((((date_.getTime() - week1.getTime()) / 86400000) - 3 + @@ -10820,156 +10159,291 @@ var lib_plankton; / 7)); } + pit_1.date_object_get_week_of_year = date_object_get_week_of_year; /** - * @author neu3no, fenris */ - function helper_englishWeekOfYear(date) { - let nr = helper_weekOfYear(date); - if (date.getDay() === 0) { - nr = nr - 1; - } - return nr; + function to_unix_timestamp(pit) { + return pit; + } + pit_1.to_unix_timestamp = to_unix_timestamp; + /** + */ + function from_unix_timestamp(unix_timestamp) { + return unix_timestamp; + } + pit_1.from_unix_timestamp = from_unix_timestamp; + /** + */ + function to_date_object(pit) { + return (new Date(pit * 1000)); + } + pit_1.to_date_object = to_date_object; + /** + */ + function from_date_object(date_object) { + return Math.round(date_object.getTime() / 1000); } /** - * @desc week of year - * @param {Date} date - * @return {int} - * @author fenris + * @todo timezone */ - function get_week(date) { - let begin_of_year = new Date(date.getFullYear(), 0, 1, 12, 0, 0); - let day_of_week = begin_of_year.getDay(); - let overhang = (day_of_week >= 4); - let factor = (1000 * 60 * 60 * 24); - let days = ((date.getTime() - begin_of_year.getTime()) / factor); - let week = (Math.ceil((days + day_of_week) / 7) - (overhang ? 1 : 0)); - return week; + function to_datetime(pit, options = {}) { + options = Object.assign({ + "timezone_shift": 0, + }, options); + return lib_plankton.call.convey(pit, [ + to_date_object, + (x) => x.getTime(), + (x) => (x + ((options.timezone_shift * (60 * 60)) * 1000)), + (x) => new Date(x), + x => x.toISOString(), + x => ({ + "timezone_shift": options.timezone_shift, + "date": { + "year": parseInt(x.slice(0, 4)), + "month": parseInt(x.slice(5, 7)), + "day": parseInt(x.slice(8, 10)), + }, + "time": { + "hour": parseInt(x.slice(11, 13)), + "minute": parseInt(x.slice(14, 16)), + "second": parseInt(x.slice(17, 19)), + }, + }) + ]); } - date_1.get_week = get_week; + pit_1.to_datetime = to_datetime; /** - * @author neu3no, fenris */ - function set_currentDate(date) { - _currentDate = date; + function from_datetime(datetime) { + return lib_plankton.call.convey(datetime, [ + (x) => lib_plankton.string.coin("{{year}}-{{month}}-{{day}}T{{hour}}:{{minute}}:{{second}}.000+{{shift}}", { + "year": x.date.year.toFixed(0).padStart(4, "0"), + "month": x.date.month.toFixed(0).padStart(2, "0"), + "day": x.date.day.toFixed(0).padStart(2, "0"), + "hour": ((x.time !== null) ? x.time.hour : 0).toFixed(0).padStart(2, "0"), + "minute": ((x.time !== null) ? x.time.minute : 0).toFixed(0).padStart(2, "0"), + "second": ((x.time !== null) ? x.time.second : 0).toFixed(0).padStart(2, "0"), + "shift": (x.timezone_shift.toFixed(0).padStart(2, "0") + ":00"), + }), + x => (new Date(x)), + from_date_object, + ]); } - date_1.set_currentDate = set_currentDate; + pit_1.from_datetime = from_datetime; /** - * @author neu3no, fenris */ - function parse(format, date = _currentDate) { - let ret = format; - let re = new RegExp("%[a-z]", "gi"); - let match; - while (match = re.exec(format)) { - ret = ret.replace(match[0], parse_segment(match[0], date)); - } - return ret; + function is_before(pit, reference) { + return (pit < reference); } - date_1.parse = parse; + pit_1.is_before = is_before; /** - * @author neu3no, fenris */ - function parse_segment(segment, date = _currentDate) { - if (!(segment in _segments)) { - let message = ("unknown format argument '" + segment + "'"); - throw (new Error(message)); - } - else { - return _segments[segment](date); - } + function is_after(pit, reference) { + return (pit > reference); } /** - * @author neu3no, fenris */ - function locale_date(date = new Date(), ignore_error = false) { - if (!(date instanceof Date)) { - if (!ignore_error) { - throw new SyntaxError("date must be instance of Date"); - } - else { - console.warn("'" + date + "' seems not to be instance of Date; try to force convert."); - let tmp = date; - date = new Date(tmp); - if ((date.toString() === "Invalid Date") - || - (!(date < new Date(0)) && !(date > new Date(0)))) { - console.warn("conversion didn't work, returning default value"); - return "Ø"; - } - } - } - let conf = ( - /* - global_config.get_value("date") - || - */ - { - "use_locale_date": true, - "format_string": "%d.%m.%Y" - }); - if (conf.use_locale_date) { - return date.toLocaleDateString(); - } - else { - return strftime.parse(conf.format_string, date); - } + function is_between(pit, reference_left, reference_right) { + return (is_after(pit, reference_left) + && + is_before(pit, reference_right)); + } + pit_1.is_between = is_between; + /** + */ + function shift_hour(pit, increment) { + return (pit + (60 * 60 * increment)); + } + /** + */ + function shift_day(pit, increment) { + return (pit + (60 * 60 * 24 * increment)); + } + pit_1.shift_day = shift_day; + /** + */ + function shift_week(pit, increment) { + return (pit + (60 * 60 * 24 * 7 * increment)); + } + pit_1.shift_week = shift_week; + /** + */ + function shift_year(pit, increment) { + return (pit + (60 * 60 * 24 * 365 * increment)); + } + /** + */ + function trunc_minute(pit) { + const datetime_input = to_datetime(pit); + const datetime_output = { + "timezone_shift": 0, + "date": { + "year": datetime_input.date.year, + "month": datetime_input.date.month, + "day": datetime_input.date.day, + }, + "time": { + "hour": ((datetime_input.time === null) + ? + 0 + : + datetime_input.time.hour), + "minute": ((datetime_input.time === null) + ? + 0 + : + datetime_input.time.minute), + "second": 0, + }, + }; + return from_datetime(datetime_output); + } + /** + */ + function trunc_hour(pit) { + const datetime_input = to_datetime(pit); + const datetime_output = { + "timezone_shift": 0, + "date": { + "year": datetime_input.date.year, + "month": datetime_input.date.month, + "day": datetime_input.date.day, + }, + "time": { + "hour": ((datetime_input.time === null) + ? + 0 + : + datetime_input.time.hour), + "minute": 0, + "second": 0, + }, + }; + return from_datetime(datetime_output); + } + /** + */ + function trunc_day(pit) { + const datetime_input = to_datetime(pit); + const datetime_output = { + "timezone_shift": 0, + "date": { + "year": datetime_input.date.year, + "month": datetime_input.date.month, + "day": datetime_input.date.day, + }, + "time": { + "hour": 0, + "minute": 0, + "second": 0, + }, + }; + return from_datetime(datetime_output); + } + /** + */ + function trunc_week(pit) { + const date_object = to_date_object(pit); + return lib_plankton.call.convey(date_object.getDay(), [ + (x) => ((x === 0) ? 7 : x), + (x) => (x - 1), + (x) => shift_day(pit, (-x)), + trunc_day + ]); + } + pit_1.trunc_week = trunc_week; + /** + */ + function trunc_month(pit) { + const datetime_input = to_datetime(pit); + const datetime_output = { + "timezone_shift": 0, + "date": { + "year": datetime_input.date.year, + "month": datetime_input.date.month, + "day": 1, + }, + "time": { + "hour": 0, + "minute": 0, + "second": 0, + }, + }; + return from_datetime(datetime_output); + } + /** + */ + function trunc_year(pit) { + const datetime_input = to_datetime(pit); + const datetime_output = { + "timezone_shift": 0, + "date": { + "year": datetime_input.date.year, + "month": 1, + "day": 1, + }, + "time": { + "hour": 0, + "minute": 0, + "second": 0, + }, + }; + return from_datetime(datetime_output); } - date_1.locale_date = locale_date; /** */ function now() { - return Math.floor(Date.now() / 1000); + return from_date_object(new Date(Date.now())); } - date_1.now = now; + pit_1.now = now; /** + * @param year year according to specified timezone shift + * @param week week according to specified timezone shift + * @return the begin of the week (monday, 00:00) */ - function from_components(components) { - return Math.floor(new Date(Date.parse(lib_string.coin("{{year}}-{{month}}-{{day}}T{{hour}}:{{minute}}:{{second}}.{{milliseconds}}{{timezone_offset}}", { - "year": components.year.toFixed(0).padStart(4, "0"), - "month": components.month.toFixed(0).padStart(2, "0"), - "day": components.day.toFixed(0).padStart(2, "0"), - "hour": components.hour.toFixed(0).padStart(2, "0"), - "minute": components.minute.toFixed(0).padStart(2, "0"), - "second": components.second.toFixed(0).padStart(2, "0"), - "milliseconds": (0).toFixed(0).padStart(3, "0"), - "timezone_offset": lib_string.coin("{{sign}}{{amount}}:00", { - "sign": ((components.timezone_offset < 0) ? "-" : "+"), - "amount": Math.abs(components.timezone_offset).toFixed(0).padStart(2, "0"), - }), - }))).getTime() - / - 1000); + function from_ywd(ywd, options = {}) { + options = Object.assign({ + "timezone_shift": 0, + }, options); + return lib_plankton.call.convey({ + "timezone_shift": options.timezone_shift, + "date": { + "year": ywd.year, + "month": 1, + "day": 1, + }, + "time": { + "hour": 0, + "minute": 0, + "second": 0 + } + }, [ + from_datetime, + (x) => shift_week(x, (ywd.week - 1)), + trunc_week, + (x) => shift_day(x, (ywd.day - 1)), + ]); } - date_1.from_components = from_components; + pit_1.from_ywd = from_ywd; /** + * @todo timezone */ - function to_components(unixtimestamp) { - const date_object = new Date(unixtimestamp * 1000); - const date_string = date_object.toISOString(); - return { - "timezone_offset": 0, - "year": parseInt(date_string.slice(0, 4)), - "month": parseInt(date_string.slice(5, 7)), - "day": parseInt(date_string.slice(8, 10)), - "hour": parseInt(date_string.slice(11, 13)), - "minute": parseInt(date_string.slice(14, 16)), - "second": parseInt(date_string.slice(17, 19)), - }; + function to_ywd(pit, options = {}) { + options = Object.assign({ + "timezone_shift": 0, + }, options); + return lib_plankton.call.convey(pit, [ + to_date_object, + x => ({ + "year": x.getFullYear(), + "week": date_object_get_week_of_year(x), + "day": ((day => (day <= 0) ? 7 : day)(x.getDay())), + }) + ]); } - date_1.to_components = to_components; - /** - */ - function get_timestamp_from_year_and_week_and_day(year, week, day) { - const d = (1 + ((week - 1) * 7)); - const date_raw = new Date(year, 0, d); - return (Math.round(date_raw.getTime() / 1000) - + - (60 * 60 * 24 * (day - date_raw.getDay() + 1))); - } - date_1.get_timestamp_from_year_and_week_and_day = get_timestamp_from_year_and_week_and_day; - })(date = lib_plankton.date || (lib_plankton.date = {})); + pit_1.to_ywd = to_ywd; + })(pit = lib_plankton.pit || (lib_plankton.pit = {})); })(lib_plankton || (lib_plankton = {})); -var strftime = lib_plankton.date; /* This file is part of »bacterio-plankton:ical«. @@ -11168,14 +10642,18 @@ var lib_plankton; throw (new Error("can not convert not utc time values")); } else { - return lib_plankton.date.from_components({ - "timezone_offset": 0, - "year": datetime.date.year, - "month": datetime.date.month, - "day": datetime.date.day, - "hour": ((datetime.time === null) ? 0 : datetime.time.hour), - "minute": ((datetime.time === null) ? 0 : datetime.time.minute), - "second": ((datetime.time === null) ? 0 : datetime.time.second), + return lib_plankton.pit.from_datetime({ + "timezone_shift": 0, + "date": { + "year": datetime.date.year, + "month": datetime.date.month, + "day": datetime.date.day, + }, + "time": { + "hour": ((datetime.time === null) ? 0 : datetime.time.hour), + "minute": ((datetime.time === null) ? 0 : datetime.time.minute), + "second": ((datetime.time === null) ? 0 : datetime.time.second), + } }); } } diff --git a/tools/update-plankton b/tools/update-plankton index 8dba347..0ba6a65 100755 --- a/tools/update-plankton +++ b/tools/update-plankton @@ -25,6 +25,7 @@ modules="${modules} server" modules="${modules} args" modules="${modules} bcrypt" modules="${modules} map" +modules="${modules} pit" modules="${modules} auth"