You are on page 1of 10

Ring Documentation, Release 1.5.

** 09 Hour (12)
** 144 Day of the year
** 05 Month of the year
** 58 Minutes after hour
** AM AM or PM
** 38 Seconds after the hour
** 21 Week of the year (sun-sat)
** 0 day of the week
** 05/24/15 date
** 09:58:38 time
** 15 year of the century
** 2015 year
** Arab Standard Time time zone
** % percent sign
*/

See TimeList()

Example:
See "Day Name : " + TimeList()[2] # Sunday

Example:
See "Month Name : " + TimeList()[4] # May

28.6 AddDays() Function

Syntax:
AddDays(cDate,nDays) ---> Date from cDate and after nDays

Example:
cDate = date()
see cDate + nl # 24/05/2015
cDate = adddays(cDate,10)
see cDate + nl # 03/06/2015

28.7 DiffDays() Function

Syntax:
DiffDays(cDate1,cDate2) ---> number of days (Date1 - Date2)

Example:
cDate1 = date()
see cDate1 + nl # 24/05/2015
cDate2 = adddays(cDate1,10)
see cDate2 + nl # 03/06/2015
see "DiffDays = " + diffdays(cDate1,cDate2) + nl # -10
see "DiffDays = " + diffdays(cDate2,cDate1) + nl # 10

28.6. AddDays() Function 205


Ring Documentation, Release 1.5.4

28.8 EpochTime() Function

Syntax:
EpochTime( cDate, cTime ) ---> Epoch Seconds

Example:
###-------------------------------------------------------------
# EpochTime()
# Example --- EpochSec = EpochTime( Date(), Time() )
# Call Format: EpochSec = EpochTime( "15/07/2016", "10:15:30" )
# EpochSec = 1468577730
#---------------------------------------------------------------

Func EpochTime(Date, Time)

arrayDate = split(Date, "/")


arrayTime = split(Time, ":")

Year = arrayDate[3] ; Month = arrayDate[2] ; Day = arrayDate[1]


Hour = arrayTime[1] ; Minute = arrayTime[2] ; Second = arrayTime[3]

cDate1 = Day +"/"+ Month +"/"+ Year


cDate2 = "01/01/" + Year
DayOfYear = DiffDays( cDate1, cDate2)

### Formula
tm_sec = Second * 1
tm_min = Minute * 60
tm_hour = Hour * 3600
tm_yday = DayOfYear * 86400
tm_year = Year - 1900

tm_year1 = ( tm_year - 70) * 31536000


tm_year2 = ( floor(( tm_year - 69) / 4 )) * 86400
tm_year3 = ( floor(( tm_year - 1) / 100 )) * 86400
tm_year4 = ( floor(( tm_year + 299) / 400 )) * 86400

### Result
EpochSec = tm_sec + tm_min + tm_hour + tm_yday + tm_year1 + tm_year2 - tm_year3 + tm_year4

return EpochSec

28.8. EpochTime() Function 206


CHAPTER

TWENTYNINE

CHECK DATA TYPE AND CONVERSION

In this chapter we are going to learn about the functions that can be used for
• Checking Data Type
• Checking Character
• Conversion

29.1 Check Data Type

The next functions can be used to check the data type


• isstring()
• isnumber()
• islist()
• type()
• isnull()

29.2 IsString() Function

Using the IsString() function we can know if the value is a string or not
Syntax:
IsString(value) ---> 1 if the value is a string or 0 if not

Example:
see isstring(5) + nl + # print 0
isstring("hello") + nl # print 1

29.3 IsNumber() Function

Using the IsNumber() function we can know if the value is a number or not
Syntax:

207
Ring Documentation, Release 1.5.4

IsNumber(value) ---> 1 if the value is a number or 0 if not

Example:
see isnumber(5) + nl + # print 1
isnumber("hello") + nl # print 0

29.4 IsList() Function

Using the IsList() function we can know if the value is a list or not
Syntax:
IsList(value) ---> 1 if the value is a list or 0 if not

Example:
see islist(5) + nl + # print 0
islist("hello") + nl + # print 0
islist([1,3,5]) # print 1

29.5 Type() Function

We can know the type of a value using the Type() Function.


Syntax:
Type(value) ---> The Type as String

Example:
see Type(5) + nl + # print NUMBER
Type("hello") + nl + # print STRING
Type([1,3,5]) # print LIST

29.6 IsNULL() Function

We can check the value to know if it’s null or not using the IsNULL() function
Syntax:
IsNULL(value) ---> 1 if the value is NULL or 0 if not

Example:
see isnull(5) + nl + # print 0
isnull("hello") + nl + # print 0
isnull([1,3,5]) + nl + # print 0
isnull("") + nl + # print 1
isnull("NULL") # print 1

29.4. IsList() Function 208


Ring Documentation, Release 1.5.4

29.7 Check Character

The next functions can be used to check character


• isalnum()
• isalpha()
• iscntrl()
• isdigit()
• isgraph()
• islower()
• isprint()
• ispunct()
• isspace()
• isupper()
• isxdigit()

29.8 IsAlNum() Function

We can test a character or a string using the IsAlNum() Function


Syntax:
IsAlNum(value) ---> 1 if the value is digit/letter or 0 if not

Example:
see isalnum("Hello") + nl + # print 1
isalnum("123456") + nl + # print 1
isalnum("ABCabc123") + nl + # print 1
isalnum("How are you") # print 0 because of spaces

29.9 IsAlpha() Function

We can test a character or a string using the IsAlpha() Function


Syntax:
IsAlpha(value) ---> 1 if the value is a letter or 0 if not

Example:
see isalpha("Hello") + nl + # print 1
isalpha("123456") + nl + # print 0
isalpha("ABCabc123") + nl + # print 0
isalpha("How are you") # print 0

29.7. Check Character 209


Ring Documentation, Release 1.5.4

29.10 IsCntrl() Function

We can test a character or a string using the IsCntrl() Function


Syntax:
IsCntrl(value) ---> 1 if the value is a control character (no printing position) or 0 if not

Example:
See iscntrl("hello") + nl + # print 0
iscntrl(nl) # print 1

29.11 IsDigit() Function

We can test a character or a string using the IsDigit() Function


Syntax:
IsDigit(value) ---> 1 if the value is a digit or 0 if not

Example:
see isdigit("0123456789") + nl + # print 1
isdigit("0123a") # print 0

29.12 IsGraph() Function

We can test a character or a string using the IsGraph() Function


Syntax:
IsGraph(value) ---> 1 if the value can be printed (Except space) or 0 if not

Example:
see isgraph("abcdef") + nl + # print 1
isgraph("abc def") # print 0

29.13 IsLower() Function

We can test a character or a string using the IsLower() Function


Syntax:
IsLower(value) ---> 1 if the value is lowercase letter or 0 if not

Example:
see islower("abcDEF") + nl + # print 0
islower("ghi") # print 1

29.10. IsCntrl() Function 210


Ring Documentation, Release 1.5.4

29.14 IsPrint() Function

We can test a character or a string using the IsPrint() Function


Syntax:
IsPrint(value) ---> 1 if the value occupies a printing position or 0 if not

Example:
see isprint("Hello") + nl + # print 1
isprint("Nice to see you") + nl + # print 1
isprint(nl) # print 0

29.15 IsPunct() Function

We can test a character or a string using the IsPunct() Function


Syntax:
IsPunct(value) ---> 1 if the value is a punctuation character or 0 if not

Example:
see ispunct("hello") + nl + # print 0
ispunct(",") # print 1

29.16 IsSpace() Function

We can test a character or a string using the IsSpace() Function


Syntax:
IsSpace(value) ---> 1 if the value is a white-space or 0 if not

Example:
see isspace(" ") + nl + # print 1
isspace("test") # print 0

29.17 IsUpper() Function

We can test a character or a string using the IsUpper() Function


Syntax:
IsUpper(value) ---> 1 if the value is an uppercase alphabetic letter or 0 if not

Example:
see isupper("welcome") + nl + # print 0
isupper("WELCOME") # print 1

29.14. IsPrint() Function 211


Ring Documentation, Release 1.5.4

29.18 IsXdigit() Function

We can test a character or a string using the IsXdigit() Function


Syntax:
IsXdigit(value) ---> 1 if the value is a hexdecimal digit character or 0 if not

Example:
see isxdigit("0123456789abcdef") + nl + # print 1
isxdigit("123z") # print 0

29.19 Conversion

The next functions can be used for conversion


• number()
• string()
• ascii()
• char()
• hex()
• dec()
• str2hex()
• hex2str()

29.20 Number() Function

We can convert strings to numbers using the Number() function or the + operator.
Syntax:
Number(string) ---> Number
0 + string ---> Number

Example:
see number("5") + 5 + nl # print 10
see 0 + "10" + 2 # print 12

29.21 String() Function

We can convert numbers to strings using the String() function or the + operator.
Syntax:
String(number) ---> String
"" + number ---> String

29.18. IsXdigit() Function 212


Ring Documentation, Release 1.5.4

Example:
see string(5) + 5 + nl # print 55
see "" + 10 + 2 # print 102

29.22 Ascii() Function

We can get the ASCII code for a letter using the Ascii() function
Syntax:
Ascii(character) ---> ASCII Code

Example:
See ascii("m") + nl + # print 109
ascii("M") # print 77

29.23 Char() Function

We can convert the ASCII code to character using the Char() function.
Syntax:
Char(ASCII Code) ---> character

Example:
See char(109) + nl + # print m
char(77) # print M

29.24 Hex() Function

We can convert decimal to hexadecimal using the Hex() function.


Syntax:
Hex(decimal) ---> hexadecimal

Example:
See hex(10) + nl + # print a
hex(200) # print c8

29.25 Dec() Function

We can convert hexadecimal to decimal using the Dec() function


Syntax:
Dec(hexadecimal) ---> decimal

29.22. Ascii() Function 213


Ring Documentation, Release 1.5.4

Example:
See dec("a") + nl + # print 10
dec("c8") # print 200

29.26 Str2hex() Function

We can convert string characters to hexadecimal characters using the Str2hex() function.
Syntax:
Str2hex(string) ---> hexadecimal string

Example:
See str2hex("hello") # print 68656c6c6f

29.27 Hex2str() Function

We can convert hexadecimal characters to string using the Hex2str() function


Syntax:
Hex2Str(Hexadecimal string) ---> string

Example:
See hex2str("68656c6c6f") # print hello

29.26. Str2hex() Function 214

You might also like