Using minutesUntil data formatter

I am trying to get back the minutes between 2 date time field in a repeat region. {{segments[0].arrival.at.minutesUntil("segments[1].departure.at")}} both dates return properly by themselves, but when I do timeUntil or minutesUntil it returns NaN. I have tried first to Date or to ISO Date or to ISO Time. None work.

You could do toTimestamp() and then subtract one from the other which would give you the difference.

I know I keep coming up with different plans for you, however due to flights crossing timezones you could land up in situations where you become a little stuck which is why the Amadeus API provides a Duration property for each leg of your entire journey regardless of if you are crossing timezones.

Look at the property for {{duration}} and it will display something like PT26H10M which you just need to format to get 26H10M

Formatting could look like {{duration.replace("PT", "").replace("H", " Hours, ").replace("M", " Minutes")}}

Result would be 26 Hours, 10 Minutes and all timezone crossing will be accounted for.

The timezone thing should not matter as I am getting the arrival of the first leg and departure of the next leg. These would be in the same timezone. {{segments[0].arrival.at}} and {{segments[1].departure.at}} . Both of these show as valid dates. example 2020-06-10T11:00:00 Just can’t seem to figure out how Wappler does the minutesUntil if that can even work in this instance.

Your original statement {{segments[0].arrival.at.minutesUntil("segments[1].departure.at")}} needs to have the double quotes taken out so it becomes {{segments[0].arrival.at.minutesUntil(segments[1].departure.at)}} or you are evaluating a dynamic data field against a literal field.

I understand and tried that but it returns NaN.

I just tested this

{{arrival.at.minutesUntil(departure.at)}}

and the output was 337

Sorry, I have to check if there is indeed a next leg. It works down the line on a non direct flight. Thank you.

I still worry about your timezone thing, but I suppose it depends on your app, if you can fly from anywhere globally to anywhere globally then timezone differences should pose a concern.

Take this Amadeus API result in JSON

{
  "meta": {
    "count": 1,
    "links": {
      "self": "https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=SYD&destinationLocationCode=DXB&departureDate=2020-08-01&returnDate=2020-08-20&adults=1&max=1"
    }
  },
  "data": [
    {
      "type": "flight-offer",
      "id": "1",
      "source": "GDS",
      "instantTicketingRequired": false,
      "nonHomogeneous": false,
      "oneWay": false,
      "lastTicketingDate": "2020-08-01",
      "numberOfBookableSeats": 2,
      "itineraries": [
        {
          "duration": "PT39H15M",
          "segments": [
            {
              "departure": {
                "iataCode": "SYD",
                "terminal": "1",
                "at": "2020-08-01T09:45:00"
              },
              "arrival": {
                "iataCode": "DEL",
                "terminal": "3",
                "at": "2020-08-01T18:35:00"
              },
              "carrierCode": "AI",
              "number": "301",
              "aircraft": {
                "code": "788"
              },
              "operating": {
                "carrierCode": "AI"
              },
              "duration": "PT13H20M",
              "id": "1",
              "numberOfStops": 0,
              "blacklistedInEU": false
            },
            {
              "departure": {
                "iataCode": "DEL",
                "terminal": "3",
                "at": "2020-08-02T16:50:00"
              },
              "arrival": {
                "iataCode": "DXB",
                "terminal": "1",
                "at": "2020-08-02T19:00:00"
              },
              "carrierCode": "AI",
              "number": "915",
              "aircraft": {
                "code": "788"
              },
              "operating": {
                "carrierCode": "AI"
              },
              "duration": "PT3H40M",
              "id": "2",
              "numberOfStops": 0,
              "blacklistedInEU": false
            }
          ]
        },
        {
          "duration": "PT27H20M",
          "segments": [
            {
              "departure": {
                "iataCode": "DXB",
                "terminal": "1",
                "at": "2020-08-20T20:50:00"
              },
              "arrival": {
                "iataCode": "DEL",
                "terminal": "3",
                "at": "2020-08-21T02:00:00"
              },
              "carrierCode": "AI",
              "number": "916",
              "aircraft": {
                "code": "788"
              },
              "operating": {
                "carrierCode": "AI"
              },
              "duration": "PT3H40M",
              "id": "3",
              "numberOfStops": 0,
              "blacklistedInEU": false
            },
            {
              "departure": {
                "iataCode": "DEL",
                "terminal": "3",
                "at": "2020-08-21T13:15:00"
              },
              "arrival": {
                "iataCode": "SYD",
                "terminal": "1",
                "at": "2020-08-22T06:10:00"
              },
              "carrierCode": "AI",
              "number": "302",
              "aircraft": {
                "code": "788"
              },
              "operating": {
                "carrierCode": "AI"
              },
              "duration": "PT12H25M",
              "id": "4",
              "numberOfStops": 0,
              "blacklistedInEU": false
            }
          ]
        }
      ],
      "price": {
        "currency": "EUR",
        "total": "994.27",
        "base": "868.00",
        "fees": [
          {
            "amount": "0.00",
            "type": "SUPPLIER"
          },
          {
            "amount": "0.00",
            "type": "TICKETING"
          }
        ],
        "grandTotal": "994.27"
      },
      "pricingOptions": {
        "fareType": [
          "PUBLISHED"
        ],
        "includedCheckedBagsOnly": true
      },
      "validatingAirlineCodes": [
        "AI"
      ],
      "travelerPricings": [
        {
          "travelerId": "1",
          "fareOption": "STANDARD",
          "travelerType": "ADULT",
          "price": {
            "currency": "EUR",
            "total": "994.27",
            "base": "868.00"
          },
          "fareDetailsBySegment": [
            {
              "segmentId": "1",
              "cabin": "ECONOMY",
              "fareBasis": "UE6MAU6F",
              "class": "U",
              "includedCheckedBags": {
                "weight": 30,
                "weightUnit": "KG"
              }
            },
            {
              "segmentId": "2",
              "cabin": "ECONOMY",
              "fareBasis": "UE6MAU6F",
              "class": "U",
              "includedCheckedBags": {
                "weight": 30,
                "weightUnit": "KG"
              }
            },
            {
              "segmentId": "3",
              "cabin": "ECONOMY",
              "fareBasis": "TE3MAU6F",
              "class": "T",
              "includedCheckedBags": {
                "weight": 30,
                "weightUnit": "KG"
              }
            },
            {
              "segmentId": "4",
              "cabin": "ECONOMY",
              "fareBasis": "TE3MAU6F",
              "class": "T",
              "includedCheckedBags": {
                "weight": 30,
                "weightUnit": "KG"
              }
            }
          ]
        }
      ]
    }
  ],
  "dictionaries": {
    "locations": {
      "DEL": {
        "cityCode": "DEL",
        "countryCode": "IN"
      },
      "DXB": {
        "cityCode": "DXB",
        "countryCode": "AE"
      },
      "SYD": {
        "cityCode": "SYD",
        "countryCode": "AU"
      }
    },
    "aircraft": {
      "788": "BOEING 787-8"
    },
    "currencies": {
      "EUR": "EURO"
    },
    "carriers": {
      "AI": "AIR INDIA"
    }
  }
}

The first mention of duration is the overall duration of all flight segments combined 39H15M to get from Sydney Australia to Dubai International
The First segment gives a
Departure at: 2020-08-01T09:45:00
Arrival at: 2020-08-01T18:35:00

Using this method {{arrival.at.minutesUntil(departure.at)}} I get 530 as a result divide by 60 minutes and I get a duration of the flight as 8 hours, 50 minutes which is vastly different to the listed duration of that segment being PT13H20M 13 hours, 20 minutes

As I say maybe for your usage this makes no difference, but I am just making sure.

Heres how you can do it. Just need to show if Index is greater than 0, 1 etc…
Connection Time:
{{(segments[0].arrival.at.minutesUntil(segments[1].departure.at)/60).floor()}} Hours
{{(segments[0].arrival.at.minutesUntil(segments[1].departure.at)%60).floor()}} Min

I see so that is giving you the time between flights awaiting at the terminal?

Yes. Just do a dmx show if $index is greater than 0. or 1 if double connect. etc…

1 Like

At least now I understand why you were not concerned with timezones, you had me super confused there for a bit.

Yeah the timezone thing is a nightmare. You cannot check on a straight (-5) value as daylight savings time comes into play. So you have to check on region, then return the offset, then calculate the difference. A lot of math especially when you are doing 100 flights. Seems to me that connection time would be an important thing, and unsure why they would just not include that.