utilitas 2001.1.147 → 2001.1.149

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/alan.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { checkSearch, distill, getOpenRouterModels, search } from './web.mjs';
2
2
  import { create as createUoid } from './uoid.mjs';
3
3
  import { packPcmToWav } from './media.mjs';
4
+ import { getZonedDateTimeISO } from './utilitas.mjs';
4
5
  import { v4 as uuidv4 } from 'uuid';
5
6
  import { EMOJI_THINKING } from './bot.mjs';
6
7
 
@@ -300,7 +301,7 @@ const tools = [
300
301
  }
301
302
  }
302
303
  },
303
- func: async () => new Date().toLocaleString(),
304
+ func: getZonedDateTimeISO,
304
305
  showRes: true,
305
306
  },
306
307
  {
@@ -1276,7 +1277,8 @@ const talk = async (request, options = {}) => {
1276
1277
  };
1277
1278
  const multiStream = async (ai, r, opts) => {
1278
1279
  ai && r && (msgs[ai] = r);
1279
- stream && await stream(packMsg(opts));
1280
+ const msg = packMsg(opts);
1281
+ stream && await stream(msg);
1280
1282
  };
1281
1283
  // first response
1282
1284
  await multiStream(null, null, PROCESSING);
package/lib/manifest.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  const manifest = {
2
2
  "name": "utilitas",
3
3
  "description": "Just another common utility for JavaScript.",
4
- "version": "2001.1.147",
4
+ "version": "2001.1.149",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",
package/lib/utilitas.mjs CHANGED
@@ -861,6 +861,34 @@ const lock = async (key, options) => {
861
861
  };
862
862
  };
863
863
 
864
+ const padDateTime = (value, size = 2) => String(value).padStart(size, '0');
865
+
866
+ const formatTimeOffset = minutes => {
867
+ const sign = minutes >= 0 ? '+' : '-';
868
+ const absMinutes = Math.abs(minutes);
869
+ return `${sign}${padDateTime(Math.floor(absMinutes / 60))}:`
870
+ + padDateTime(absMinutes % 60);
871
+ };
872
+
873
+ const getZonedDateTimeISO = () => {
874
+ const date = new Date();
875
+ const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
876
+ const p = {
877
+ year: date.getFullYear(),
878
+ month: date.getMonth() + 1,
879
+ day: date.getDate(),
880
+ hour: date.getHours(),
881
+ minute: date.getMinutes(),
882
+ second: date.getSeconds(),
883
+ millisecond: date.getMilliseconds(),
884
+ offset: -date.getTimezoneOffset(),
885
+ };
886
+ return `${padDateTime(p.year, 4)}-${padDateTime(p.month)}-${padDateTime(p.day)}`
887
+ + `T${padDateTime(p.hour)}:${padDateTime(p.minute)}:`
888
+ + `${padDateTime(p.second)}.${padDateTime(p.millisecond, 3)}`
889
+ + `${formatTimeOffset(p.offset)}[${timeZone}]`;
890
+ };
891
+
864
892
  export {
865
893
  __,
866
894
  analyzeModule,
@@ -917,6 +945,7 @@ export {
917
945
  getTimeIcon,
918
946
  getType,
919
947
  getUnixTimestampByDate,
948
+ getZonedDateTimeISO,
920
949
  hexDecode,
921
950
  hexEncode,
922
951
  humanReadableBoolean,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "utilitas",
3
3
  "description": "Just another common utility for JavaScript.",
4
- "version": "2001.1.147",
4
+ "version": "2001.1.149",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",