Skip to content

Commit

Permalink
refactored date from string function
Browse files Browse the repository at this point in the history
  • Loading branch information
knowthelist committed Jan 28, 2024
1 parent 8ab90f0 commit e4d4c73
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 10 deletions.
77 changes: 77 additions & 0 deletions controls_ftui.txt
Original file line number Diff line number Diff line change
Expand Up @@ -670,3 +670,80 @@ UPD 2022-11-13_21:55:10 948 www/ftui/icons/truck.svg
UPD 2022-11-13_21:55:11 2027 www/ftui/icons/tty.svg
UPD 2022-11-13_21:55:12 697 www/ftui/icons/tv.svg
UPD 2022-11-13_21:55:12 1326 www/ftui/icons/umbrella.svg
UPD 2022-11-13_21:55:13 1343 www/ftui/icons/universal-access.svg
UPD 2022-11-13_21:55:14 537 www/ftui/icons/unlock-alt.svg
UPD 2022-11-13_21:55:14 542 www/ftui/icons/unlock.svg
UPD 2022-11-13_21:55:15 982 www/ftui/icons/upload.svg
UPD 2022-11-13_21:55:16 1169 www/ftui/icons/usb.svg
UPD 2022-11-13_21:55:17 674 www/ftui/icons/user-circle-o.svg
UPD 2022-11-13_21:55:18 605 www/ftui/icons/user-circle.svg
UPD 2022-11-13_21:55:19 1304 www/ftui/icons/user-md.svg
UPD 2022-11-13_21:55:20 783 www/ftui/icons/user-o.svg
UPD 2022-11-13_21:55:21 1022 www/ftui/icons/user-plus.svg
UPD 2022-11-13_21:55:22 1442 www/ftui/icons/user-secret.svg
UPD 2022-11-13_21:55:23 1437 www/ftui/icons/user-times.svg
UPD 2022-11-13_21:55:24 510 www/ftui/icons/user.svg
UPD 2022-11-13_21:55:25 1320 www/ftui/icons/venus-double.svg
UPD 2022-11-13_21:55:25 1483 www/ftui/icons/venus-mars.svg
UPD 2022-11-13_21:55:26 640 www/ftui/icons/venus.svg
UPD 2022-11-13_21:55:27 593 www/ftui/icons/video-camera.svg
UPD 2022-11-13_21:55:27 1857 www/ftui/icons/volume-control-phone.svg
UPD 2022-11-13_21:55:28 711 www/ftui/icons/volume-down.svg
UPD 2022-11-13_21:55:29 444 www/ftui/icons/volume-off.svg
UPD 2022-11-13_21:55:29 1595 www/ftui/icons/volume-up.svg
UPD 2022-11-13_21:55:30 736 www/ftui/icons/washing-machine.svg
UPD 2022-11-13_21:55:31 890 www/ftui/icons/weather-cloud.svg
UPD 2022-11-13_21:55:31 991 www/ftui/icons/weather-night.svg
UPD 2022-11-13_21:55:32 1492 www/ftui/icons/weather-partly-lightning.svg
UPD 2022-11-13_21:55:33 1184 www/ftui/icons/weather.svg
UPD 2022-11-13_21:55:33 1270 www/ftui/icons/weather3.svg
UPD 2022-11-13_21:55:34 1209 www/ftui/icons/whatsapp.svg
UPD 2022-11-13_21:55:35 1265 www/ftui/icons/wheelchair-alt.svg
UPD 2022-11-13_21:55:35 815 www/ftui/icons/wheelchair.svg
UPD 2022-11-13_21:55:36 1174 www/ftui/icons/wifi.svg
UPD 2022-11-13_21:55:37 1083 www/ftui/icons/wikipedia.svg
UPD 2022-11-13_21:55:37 657 www/ftui/icons/wind.svg
UPD 2022-11-13_21:55:38 348 www/ftui/icons/window-closed-variant.svg
UPD 2022-11-13_21:55:39 442 www/ftui/icons/window-closed.svg
UPD 2022-11-13_21:55:40 401 www/ftui/icons/window-maximize.svg
UPD 2022-11-13_21:55:40 356 www/ftui/icons/window-minimize.svg
UPD 2022-11-13_21:55:41 394 www/ftui/icons/window-open-variant.svg
UPD 2022-11-13_21:55:41 462 www/ftui/icons/window-open.svg
UPD 2022-11-13_21:55:42 581 www/ftui/icons/window-restore.svg
UPD 2022-11-13_21:55:43 426 www/ftui/icons/window-shutter-alert.svg
UPD 2022-11-13_21:55:43 306 www/ftui/icons/window-shutter-open.svg
UPD 2022-11-13_21:55:44 418 www/ftui/icons/window-shutter.svg
UPD 2022-11-13_21:55:45 355 www/ftui/icons/windows.svg
UPD 2022-11-13_21:55:46 971 www/ftui/icons/windy.svg
UPD 2022-11-13_21:55:46 1151 www/ftui/icons/windy1.svg
UPD 2022-11-13_21:55:47 1284 www/ftui/icons/windy2.svg
UPD 2022-11-13_21:55:48 822 www/ftui/icons/wpforms.svg
UPD 2022-11-13_21:55:48 798 www/ftui/icons/wrench.svg
UPD 2022-11-13_21:55:50 777 www/ftui/icons/youtube-play.svg
CRE 2022-10-10_21:13:38 10234 www/ftui/index.html
UPD 2020-12-31_16:39:06 445455 www/ftui/modules/chart.js/chart.js
UPD 2022-01-31_15:27:32 192031 www/ftui/modules/chart.js/chart.min.js
UPD 2020-12-31_16:39:06 49580 www/ftui/modules/chart.js/chartjs-adapter-date-fns.bundle.min.js
UPD 2021-02-04_22:43:17 8388 www/ftui/modules/circle-menu/circle-menu.js
UPD 2021-02-01_19:44:50 5063 www/ftui/modules/circle-menu/circle-menu.min.js
UPD 2022-05-25_18:05:01 14463 www/ftui/modules/ftui/fhem.service.js
UPD 2024-01-24_21:38:22 8347 www/ftui/modules/ftui/ftui.app.js
UPD 2024-01-19_17:33:44 13029 www/ftui/modules/ftui/ftui.binding.js
UPD 2024-01-28_13:19:50 14412 www/ftui/modules/ftui/ftui.helper.js
UPD 2020-12-31_16:39:06 9247 www/ftui/modules/hocon/hocon.js
UPD 2020-12-31_16:39:06 3192 www/ftui/modules/hocon/hocon.min.js
UPD 2021-10-13_09:24:35 65090 www/ftui/modules/iro.js/iro.js
UPD 2021-10-13_09:27:11 31699 www/ftui/modules/iro.js/iro.min.js
UPD 2022-02-16_09:23:36 24903 www/ftui/modules/rangeable/rangeable.js
UPD 2020-12-31_16:39:06 4564 www/ftui/modules/rangeable/rangeable.min.css
UPD 2022-02-16_09:23:29 12205 www/ftui/modules/rangeable/rangeable.min.js
UPD 2020-12-31_16:39:06 1922 www/ftui/modules/vanilla-notify/vanilla-notify.css
UPD 2022-02-22_21:49:40 6445 www/ftui/modules/vanilla-notify/vanilla-notify.js
UPD 2022-02-22_21:49:45 3461 www/ftui/modules/vanilla-notify/vanilla-notify.min.js
UPD 2022-11-26_13:38:29 3499 www/ftui/themes/bright-theme.css
UPD 2022-10-19_18:47:16 3933 www/ftui/themes/color-attributes.css
UPD 2022-11-13_22:32:20 3412 www/ftui/themes/ftui-theme.css
UPD 2022-02-18_19:18:46 3441 www/ftui/themes/mobile-dark-theme.css
UPD 2022-10-07_23:31:09 3781 www/ftui/themes/mobile-theme.css
UPD 2022-02-13_20:51:12 3506 www/ftui/themes/retro-theme.css
UPD 2022-02-01_22:18:11 3454 www/ftui/themes/vivid-theme.css
21 changes: 11 additions & 10 deletions www/ftui/modules/ftui/ftui.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,17 @@ export function capitalize(s) {
// date functions

export function dateFromString(str) {
const m = str.match(/(\d+)-(\d+)-(\d+)[_\s](\d+):(\d+):(\d+).*/);
const m2 = str.match(/^(\d+)$/);
const m3 = str.match(/(\d\d).(\d\d).(\d\d\d\d)/);
const m4 = str.match(/(\d\d\d\d)-(\d\d)-(\d\d)/);
const offset = new Date().getTimezoneOffset();

return (m) ? new Date(+m[1], +m[2] - 1, +m[3], +m[4], +m[5], +m[6])
: (m2) ? new Date(70, 0, 1, 0, 0, m2[1], 0)
: (m3) ? new Date(+m3[3], +m3[2] - 1, +m3[1], 0, -offset, 0, 0)
: (m4) ? new Date(+m4[1], +m4[2] - 1, +m4[3], 0, -offset, 0, 0): new Date();
if (str && str.match(/(\d+)-(\d+)-(\d+)[_\s](\d+):(\d+):(\d+).*/)){
return new Date(+m[1], +m[2] - 1, +m[3], +m[4], +m[5], +m[6]);
} else if (str && str.match(/(\d\d).(\d\d).(\d\d\d\d)/)) {
return new Date(+m3[3], +m3[2] - 1, +m3[1], 0, -offset, 0, 0);
} else if (str && str.match(/(\d\d\d\d)-(\d\d)-(\d\d)/)) {
return new Date(+m4[1], +m4[2] - 1, +m4[3], 0, -offset, 0, 0);
} else if (str && str.match(/^(\d+)$/)) {
return new Date(70, 0, 1, 0, 0, m2[1], 0);
} else {
return new Date();
}
}

export function dateFormat(date, format) {
Expand Down

0 comments on commit e4d4c73

Please sign in to comment.