Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Commit

Permalink
Add timezone to Device
Browse files Browse the repository at this point in the history
Bug: 178737106

Change-Id: I8ddf7d1671effb1a6cf1dceb13b844ba1ada98b5
  • Loading branch information
taycaldwell committed Apr 22, 2021
1 parent ebcdd2b commit 5f48609
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Add timezone field to Device

## [3.5.0]
### Added
Expand Down
23 changes: 23 additions & 0 deletions src/api/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ export interface Device {
* which fields are set depending on coarse vs. fine grained permission.
*/
currentLocation?: Location
/**
* Optional. Timezone associated with the request used to resolve datetime values. If not
* set, "UTC" is used.
*/
timeZone?: TimeZone
}

export enum Capability {
Expand Down Expand Up @@ -155,6 +160,24 @@ export interface Location {
postalAddress?: PostalAddress
}

/**
* Optional. Timezone associated with the request used to resolve datetime values. If not
* set, "UTC" is used.
*
* Represents a time zone from the [IANA Time Zone
* Database](https://www.iana.org/time-zones).
*/
export interface TimeZone {
/**
* IANA Time Zone Database time zone, e.g. "America/New_York".
*/
id?: string
/**
* Optional. IANA Time Zone Database version number, e.g. "2019a".
*/
version?: string
}

/**
* Required. Information to fulfillment on how to handle the request. For example a request
* intending to get a fact might have a handler with a name of "getFact".
Expand Down
6 changes: 5 additions & 1 deletion src/conversation/_test/conversation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ function requestBuilder(handlerName: string, slots: Record<string, Schema.Slot>)
organization: '',
},
},
timeZone: {
id: 'America/New_York',
version: '2019a',
}
},
}
}
Expand Down Expand Up @@ -187,7 +191,7 @@ test('device passed to conv', async t => {
const webhookRequest = requestBuilder(handlerName, {})
const app = conversation()
app.handle(handlerName, conv => {
t.deepEqual(JSON.stringify(clone(conv.device)), JSON.stringify(clone(webhookRequest.device)))
t.deepEqual(clone(conv.device), clone(webhookRequest.device as Schema.Device))
})
await app.handler(webhookRequest as Schema.HandlerRequest, {})
})
Expand Down
8 changes: 7 additions & 1 deletion src/conversation/handler/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ export class Device {
* @public
*/
capabilities: Schema.Capability[]
/**
* Optional. Timezone associated with the request used to resolve datetime values. If not
* set, "UTC" is used.
*/
timeZone?: Schema.TimeZone

/**
* Optional. The device location of the user. Note, this is only populated after location
Expand All @@ -41,9 +46,10 @@ export class Device {

/** @hidden */
constructor(input: Schema.Device = {}) {
const { capabilities = [], currentLocation = {} } = input
const { capabilities = [], currentLocation = {}, timeZone = {} } = input
this.capabilities = capabilities
this.currentLocation = currentLocation
this.timeZone = timeZone
}

}

0 comments on commit 5f48609

Please sign in to comment.