Wxs formats the timestamp as customized

I use wxs on wepy. The following section of the original js code that formats the timestamp that I have tested in the html file is normal.
now it"s time to change it to the syntax supported by wxs. But the regular understanding of js is still relatively poor, tested many times but still can not correctly change the RegExp.

The code for

wxml to call this method is:

<view class="item-time">{{timeFilter.getTime(item.create_time, "yyyy-MM-dd hh:mm:ss")}}</view>
The

js section introduces this wxs code as follows:

import timeFilter from "../wxs/filter.wxs"
wxs = {
      timeFilter
    }

here is the complete code of the filter.wxs
the two parameters passed in by the getTime method, time is the timestamp (accurate to seconds), fmt is yyyy-mm-dd).

module.exports = {

  getTime: function (time, fmt) {
    if (!time) return ""

    var date = getDate(time * 1000)

    var o = {
      "M+": date.getMonth() + 1,               // 
      "d+": date.getDate(),                    // 
      "h+": date.getHours(),                   // 
      "m+": date.getMinutes(),                 // 
      "s+": date.getSeconds(),                 // 
      "q+": Math.floor((date.getMonth() + 3) / 3), // 
      "S": date.getMilliseconds()             // 
    }
    if (/(y+)/.test(fmt)) {
      fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length))
    }
    for (var k in o) {
      if (new RegExp("(" + k + ")").test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)))
      }
    }
    return fmt
  }
}

if you use the above code directly, the error message is as follows:

ask all the gods to help modify it, thank you very much!

Apr.04,2021

wxs has no speed advantage on Android, and WeChat Mini Programs's own experience on ios is the same.
it is not recommended to write wxs

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b37171-2c061.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b37171-2c061.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?