data fixes; indicator=>workspace sync
This commit is contained in:
23
web/src/utils.ts
Normal file
23
web/src/utils.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Convert a TradingView interval string to seconds.
|
||||
* Plain numbers are minutes (TradingView convention), suffixed forms use the suffix.
|
||||
* Examples: "15" → 900, "1D" → 86400, "1W" → 604800
|
||||
*/
|
||||
export function intervalToSeconds(interval: string): number {
|
||||
const numericInterval = parseInt(interval)
|
||||
if (!isNaN(numericInterval) && interval === numericInterval.toString()) {
|
||||
return numericInterval * 60 // plain number = minutes
|
||||
}
|
||||
const match = interval.match(/^(\d+)([SMHDW])$/)
|
||||
if (match) {
|
||||
const value = parseInt(match[1])
|
||||
switch (match[2]) {
|
||||
case 'S': return value
|
||||
case 'M': return value * 60
|
||||
case 'H': return value * 3600
|
||||
case 'D': return value * 86400
|
||||
case 'W': return value * 604800
|
||||
}
|
||||
}
|
||||
return 60 // fallback: 1 minute
|
||||
}
|
||||
Reference in New Issue
Block a user