# 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](../../variable-data-types/the-number-variable-data-type), 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:

```javascript
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](../../variable-data-types/the-time-variable-data-type) 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:

```json
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`:

```javascript
time2 > time1 -> TRUE
time2 >= time1 -> TRUE
time1 > time2 -> FALSE
time1 >= time2 -> FALSE
```

Likewise, `time1` is less than `time2`:

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

## Dates

When comparing the ordering of [Date](../../variable-data-types/the-date-variable-data-type) 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:

```json
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`:

```javascript
date2 > date1 -> TRUE
date2 >= date1 -> TRUE
date1 > date2 -> FALSE
date1 >= date2 -> FALSE
```

Likewise, `date1` is less than `date2`:

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

## DateTimes

When comparing the ordering of [DateTime](../../variable-data-types/the-datetime-variable-data-type) 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:

```json
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`:

```javascript
datetime2 > datetime1 -> TRUE
datetime2 >= datetime1 -> TRUE
datetime1 > datetime2 -> FALSE
datetime1 >= datetime2 -> FALSE
```

Likewise, `datetime1` is less than `datetime2`:

```javascript
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:

```json
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:

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

## Currencies

When comparing the ordering of [Currencies](../../variable-data-types/the-currency-variable-data-type), 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:

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

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

```javascript
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`:

```javascript
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 of`precision`, 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:

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

`currency_3` represents thirty US dollars, just like`currency_2` does; the only difference is precision:

```javascript
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](../../variable-data-types/the-text-variable-data-type), ordering operators compare lexicographical order.

<details>

<summary>What is lexicographical order?</summary>

\


"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).

</details>

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:

```javascript
"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:

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