5

I'm trying to develop an Alexa skill, and I need to get the relative time, eg: "5 minutes ago".

I have defined a time slot for my skill which accepts time like 5 minutes, 6.30 am or 4 in the morning. But I'm not able to accept a time like 5 minutes ago. I new to Alexa and can some one help me out with this

{
  "slots": [
    {
      "name": "time",
      "type": "AMAZON.TIME"
    }
  ],
  "intent": "ReportTime"
}
Nidhin S G
  • 1,685
  • 2
  • 15
  • 45
  • @Connum answer below is a great start. Just beware that you may run into timezone related issues unless you request zip code information and can handle that yourself, see this thread: https://stackoverflow.com/questions/44072625/how-do-i-get-a-users-date-time-or-timezone-information-for-an-alexa-skill – Josep Valls Jul 19 '17 at 20:13
  • So right now skills do not support date/time in the past? – StErMi May 31 '18 at 11:02

1 Answers1

3

You could add a {modifier} slot that can take several keywords like "ago" and "from now". The intent could then have something like the following utterances:

{
  "name": "TimeTest",
  "samples": [
    "what happened {time} {modifier}",
    "what will happen {time} {modifier}"
  ],
  "slots": [
    {
      "name": "time",
      "type": "AMAZON.TIME",
      "samples": []
    },
    {
      "name": "modifier",
      "type": "custom_time_modifier",
      "samples": []
    }
  ]
}

with the following custom modifier type:

"types": [
{
  "name": "custom_time_modifier",
  "values": [
    {
      "id": null,
      "name": {
        "value": "ago",
        "synonyms": [
          "in the past"
        ]
      }
    },
    {
      "id": null,
      "name": {
        "value": "from now",
        "synonyms": [
          "in the future"
        ]
      }
    }
  ]
}
Constantin Groß
  • 10,719
  • 4
  • 24
  • 50