Explorar el Código

+getTimeCodeFromSeconds

Ivan Asmer hace 4 años
padre
commit
6080d17669
Se han modificado 1 ficheros con 8 adiciones y 1 borrados
  1. 8 1
      index.mjs

+ 8 - 1
index.mjs

@@ -9,6 +9,13 @@ const getSecondsFromTimeCode = timeCode => {
                     (times.length === 3 ? times[0]*60*60 + times[1]*60 + times[2] : NaN )
 }
 
+const getTimeCodeFromSeconds = seconds => {
+    let hours   = Math.floor(seconds / 3600)
+    let minutes = Math.floor((seconds % 3600) / 60)
+    let seconds = Math.floor((seconds % 3600) % 60)
+    return `${hours}:${minutes}:${seconds}`
+}
+
 const getTimeCodes = ast =>{
     let timeCodes = {}
     const walker = node => ((node.tag && node.tag.startsWith('heading') && (timeCodes[node.startMatch[4] || node.startMatch[3]] = node.startMatch[3])), 
@@ -702,4 +709,4 @@ function toReact(ast, React, mapMDToComponents=defaultMapMDToComponents){
     return _(RenderComponent, props)
 }
 
-export {buildAST, toReact, getSecondsFromTimeCode, getTimeCodes, defaultMapMDToComponents}
+export {buildAST, toReact, getSecondsFromTimeCode, getTimeCodes, defaultMapMDToComponents , getTimeCodeFromSeconds}