Stringify - Timeframe Enumeration --> String
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © DasanC

//@version=5

// @description Cast variable types and enumerations to human-readable Strings
library("Stringify")

// @function Cast a timeframe enumeration to readable string. 
// @param string `x` is a timeframe enumeration ('3D', '120', '15', '5s' ...)
// @returns A string representation of the timeframe or 'NA' if `x` is `na`
export timeframe(string T) =>
	x = T
	if x == ''
		x := timeframe.period
	if na(x) 
		'NA'
	else
		string period = switch str.upper(str.substring(x,str.length(x)-1))
			'S' => str.lower(x)	//Seconds Timeframe
			'D' => str.upper(x)	//Daily Timeframe
			'W' => str.upper(x)	//Weekly Timeframe
			'M' => str.upper(x)	//Monthly Timeframe
            //Default Case (Hour and/or Minutes)
			=> str.tonumber(x) < 60 ? x + 'm'
			     : str.tonumber(x)%60 == 0 ? str.tostring(str.tonumber(x)/60) + 'H'
				 : str.format("{0,number,integer}H {1,number,integer}m",math.floor(str.tonumber(str.replace(x,'S',''))/60),str.tonumber(str.replace(x,'S',''))%60)

Sample_Timeframe = input.timeframe('61',"Sample Timeframe Input")

if barstate.islast
	label.new(bar_index,close,timeframe(Sample_Timeframe),color=chart.fg_color,textcolor = chart.bg_color)