Ordering (<, <=, > , >=)

Airscript supports the following ordering comparison operators: greater than (>), greater than or equal to (>=), less than (<), and less than or equal to (<=).

Numbers

When comparing the ordering of Numbers, ordering operators output TRUE if the described relationship is true, and FALSE is the described relationship is false. For example, the fact that 2 is greater than 1 results in the following:

1 < 2 -> TRUE  
1 <= 2 -> TRUE  
1 < 1 -> FALSE  
1 <= 1 -> TRUE  
1 > 2 -> FALSE  
1 >= 2 -> FALSE  
1 > 1 -> FALSE  
1 >= 1 -> TRUE

Times

When comparing the ordering of Time values, ordering operators consider the time later in the day to be "greater than" the other.

For the sake of example, say that there are two Time variables, defined as follows:

time1 -> {
  "hour": 11,
  "minute": 27,
  "second": 42,
  "millisecond": 0
}
time2 -> {
  "hour": 12,
  "minute": 42,
  "second": 48,
  "millisecond": 0
}

time2 represents a time of day that is over an hour after time1. This means that time2 is greater than time1:

time2 > time1 -> TRUE
time2 >= time1 -> TRUE
time1 > time2 -> FALSE
time1 >= time2 -> FALSE

Likewise, time1 is less than time2:

time2 < time1 -> FALSE
time2 <= time1 -> FALSE
time1 < time2 -> TRUE
time1 <= time2 -> TRUE

Dates

When comparing the ordering of Date values, ordering operators consider the later date to be "greater than" the other.

For the sake of example, say that there are two Time variables, defined as follows:

date1 ->{
  "day": 28,
  "month": 2,
  "year": 2022
}
date2 -> {
  "day": 8,
  "month": 8,
  "year": 2022
}

date2 represents day that comes after date1. This means that date2 is greater than date1:

date2 > date1 -> TRUE
date2 >= date1 -> TRUE
date1 > date2 -> FALSE
date1 >= date2 -> FALSE

Likewise, date1 is less than date2:

date2 < date1 -> FALSE
date2 <= date1 -> FALSE
date1 < date2 -> TRUE
date1 <= date2 -> TRUE

DateTimes

When comparing the ordering of DateTime values, ordering operators consider the later described time to be "greater than" the other.

For the sake of example, say that there are two DateTime variables, defined as follows:

datetime1 ->{
  "date": {
    "day": 1,
    "month": 2,
    "year": 2021
  },
  "time": {
    "hour": 12,
    "minute": 43,
    "second": 7,
    "millisecond": 0
  },
  "timeZone": "UTC"
}
datetime2 -> {
  "date": {
    "day": 8,
    "month": 2,
    "year": 2022
  },
  "time": {
    "hour": 12,
    "minute": 43,
    "second": 13,
    "millisecond": 0
  },
  "timeZone": "UTC"
}

datetime2 represents a time that comes after datetime1. This means that datetime2 is greater than datetime1:

datetime2 > datetime1 -> TRUE
datetime2 >= datetime1 -> TRUE
datetime1 > datetime2 -> FALSE
datetime1 >= datetime2 -> FALSE

Likewise, datetime1 is less than datetime2:

datetime2 < datetime1 -> FALSE
datetime2 <= datetime1 -> FALSE
datetime1 < datetime2 -> TRUE
datetime1 <= datetime2 -> TRUE

Note that while both datetime1 and datetime2 are in the same timezone, this does need to be the case in order for the comparison operators to properly compare them. For instance, say there is another DateTime variable, defined as follows:

datetime3 -> {
  "date": {
    "day": 8,
    "month": 2,
    "year": 2022
  },
  "time": {
    "hour": 15,
    "minute": 43,
    "second": 13,
    "millisecond": 0
  },
  "timeZone": "Africa/Dar_es_Salaam"
}

datetime3 represents the exact same time as datetime2, just in the Africa/Dar_es_Salaam timezone rather than UTC:

datetime2 >= datetime3 -> TRUE
datetime2 <= datetime3 -> TRUE
datetime2 > datetime3 -> FALSE
datetime2 < datetime3 -> FALSE

Currencies

When comparing the ordering of Currencies, ordering operators compare the described currency value, taking precision into account. Currencies with different currency codes cannot be compared; Airscript will throw an error.

For the sake of example, say that there are two Currency variables, defined as follows:

currency_1 -> {
  "amount": 1000,
  "code": "USD",
  "precision": 2
}
currency_2 -> {
  "amount": 3000,
  "code": "USD",
  "precision": 2
}

currency_1 represents ten US dollars while currency_2represents thirty US dollars.
This means that currency_2 is greater than currency_1:

currency_2 > currency 1 -> TRUE
currency_2 >= currency 1 -> TRUE
currency_1 > currency 2 -> FALSE
currency_1 >= currency 2  -> FALSE

Likewise, currency_1 is less than currency_2:

currency_2 < currency_1 -> FALSE
currency_2 <= currency_1 -> FALSE
currency_1 < currency_2 -> TRUE
currency_1 <= currency_2 -> TRUE

Note that while both currency_1 and currency_2 compare currency with the same values ofprecision, this does need to be the case in order for the comparison operators to properly compare them. For instance, say there is another Currency variable, defined as follows:

currency_3 -> {
  "amount": 30,
  "code": "USD",
  "precision": 0
}

currency_3 represents thirty US dollars, just likecurrency_2 does; the only difference is precision:

currency_2 >= currency_3 -> TRUE
currency_2 <= currency_3 -> TRUE
currency_2 > currency_3 -> FALSE
currency_2 < currency_3 -> FALSE

Strings

When comparing the ordering of strings, ordering operators compare lexicographical order.

What is lexicographical order?

"Lexicographical" is derived from the word "lexicon," meaning the set of characters used in a language. The characters in a lexicon have a conventional ordering, such as the letters in the English alphabet. Putting words in alphabetical order is putting them in lexicographical order.

While the letters in the English alphabet have a well-established order, their place in relation to non-letter characters is less standardized. There exist variants of lexicographical ordering that arrange some non-letter characters differently. The variant used by Airscript places lowercase letters before capital, symbols and punctuation before numbers, numbers before letters, and empty spaces before occupied spaces (that is, shorter strings before longer strings).

When a string is "greater than" another, this means that it comes after the other string in lexicographical order. For instance, the string "airscript" comes after the string "air" in lexicographical order, meaning that "airscript" is greater than "air". This results in the following:

"air" > "airscript" -> FALSE  
"airscript" > "air" -> TRUE
"air" >= "airscript" -> FALSE  
"airscript" > "airscript" -> FALSE  
"airscript" >= "airscript" -> TRUE

Similarly, when a string is "less than" another, this means that it comes before the other string in lexicographical order. For instance, the string "air" is less than the string "airscript". This results in the following:

"air" < "airscript" -> TRUE 
"airscript" < "air" -> FALSE 
"air" <= "airscript" -> TRUE  
"airscript" < "airscript" -> FALSE  
"airscript" <= "airscript" -> TRUE