Time Basic Process Flow

Overview

Once the TimeQuery Flow is executed, Time related variables are calculated using datetime object and default time zone, which is in turn calculated using the Default location set by Human.

Below snippet has the list of variables (Current, Previous and Next) calculated to answer Basic time related questions.

## Used for calculation of current time related variables
current_time = datetime.datetime.now(pytz.timezone(getDefaultTimeZone()))
currentyear = current_time.year
currentmonthnum = current_time.month
currentmonthname = monthname(str(currentmonthnum))
currentday = current_time.day
currentweekdayname = weekdayname(0,current_time)

## Used for calculation of previous time related variables
previousyear = str(currentyear -1)
previousmonth = monthname(str(currentmonthnum -1))
previousday = str(currentday-1)
previousweekdayname =weekdayname(1,current_time)

## Used for calculation of next time related variables
nextyear = str(currentyear + 1)
nextmonth = monthname(str(currentmonthnum + 1))
nextday = str(currentday+1)
nextweekdayname =weekdayname(6,current_time)

"Current Time" Calculations

You would have noticed that in snippet above, all the parameters are simple Calendar based calculations on Current Time

So the Flow Starts with Getting the Current Time,

  • Which is calculated by datetime.datetime.now()

  • To make it more efficient time zone is passed using pytz package.

  • Time zone also is dynamically calculated using tzwhere package, it is calculated using Latitude and Longitude of the default location set by Human

current_time = datetime.datetime.now(pytz.timezone(getDefaultTimeZone()))

getDefaultTimeZone flow is used to get the Default Time Zone, First Latitude and Longitude are Identified for the default home city parameter and thereafter Time Zone Process Flow is use to get the Time Zone value.

city_name = homeCityName
LatitudeValue,LongitudeValue =  geoLocateLatitudeLongitude(city_name)
timeZone = getTimeZoneValue(LatitudeValue, LongitudeValue)

Once we get the Time Zone, Pytz package is used to convert the time zone into date time format needed by datetime object. Datetime now() function is then used to get the current time.

pytz package is used to convert the Time Zone into format suitable for date time conversions.

Now Aryan already knows all the Previous Time Query parameters related value as mentioned in start of this section, Thus requested keyword is identified and respective results are provided to the Human as mentioned in the snippet below.

if subStrCheck(text,"previous"):
    if subStrCheck(text,"date"):
        result = "Previous Date was " + str(previousday) + " " + currentmonthname + " " + str(currentyear)
    elif subStrCheck(text,"day"):
        result = "Previous Day was " + str(previousweekdayname)
    elif subStrCheck(text,"month"):
        result = "Previous Month was " + str(previousmonth)
    elif subStrCheck(text,"year"):
        result = "Previous Year was " + str(previousyear)
    else: 
        result = "Previous Date was " + str(previousday) + " " + currentmonthname + " " + str(currentyear)

Now Aryan already knows all the Next Time Query parameters related value as mentioned in start of this section, Thus requested keyword is identified and respective results are provided to the Human as mentioned in the snippet below.

    elif subStrCheck(text,"next"):
        if subStrCheck(text,"date"):
            result = "Next Date will be " + str(nextday) + " " + currentmonthname + " " + str(currentyear)
        elif subStrCheck(text,"day"):
            result = "Next Day will be " + str(nextweekdayname)
        elif subStrCheck(text,"month"):
            result = "Next Month will be " + str(nextmonth)
        elif subStrCheck(text,"year"):
            result = "Next Year will be " + str(nextyear)
        else: 
            result = "Next Date will be " + str(nextday) + " " + currentmonthname + " " + str(currentyear)

Now Aryan already knows all the Current Time Query parameters related value as mentioned in start of this section, Thus requested keyword is identified and respective results are provided to the Human as mentioned in the snippet below.

Only Exception to the above statement is that for Current Time Across Time Zone control is passed to getCurrentTime flow which used Time Zone for that location to get the Current Time. Time Across Globe mentioned this Flow

else:
    if subStrCheck(text,"date"):
        result = "Current Date is " + str(currentday) + " " + currentmonthname + " " + str(currentyear)
    elif subStrCheck(text,"day"):
        result = "Current Day is " + str(currentweekdayname)
    elif subStrCheck(text,"month"):
        result = "Current Month is " + str(currentmonthname)
    elif subStrCheck(text,"year"):
        result = "Current Year is " + str(currentyear)
    elif subStrCheck(text,"time"):
        zone, currenttime = getCurrentTime(aifriend,rawspeech)
        result = "Current " + str(zone) + " time is " + str(currenttime)
    else:
        result = "Current Date is " + str(currentday) + " " + currentmonthname + " " + str(currentyear)

Last updated