diff --git a/common/changes/@typespec/compiler/add-unixtimestamp32_2023-10-17-19-30.json b/common/changes/@typespec/compiler/add-unixtimestamp32_2023-10-17-19-30.json new file mode 100644 index 0000000000..c5b621fc64 --- /dev/null +++ b/common/changes/@typespec/compiler/add-unixtimestamp32_2023-10-17-19-30.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@typespec/compiler", + "comment": "Add new `unixTimestamp32` scalar to standard library", + "type": "none" + } + ], + "packageName": "@typespec/compiler" +} \ No newline at end of file diff --git a/docs/standard-library/built-in-data-types.md b/docs/standard-library/built-in-data-types.md index 9badf3d43e..5401baf9d3 100644 --- a/docs/standard-library/built-in-data-types.md +++ b/docs/standard-library/built-in-data-types.md @@ -394,6 +394,17 @@ scalar uint8 +### `unixTimestamp32` {#unixTimestamp32} + +Represent a 32-bit unix timestamp datetime with 1s of granularity. +It measures time by the number of seconds that have elapsed since 00:00:00 UTC on 1 January 1970. + +```typespec +scalar unixTimestamp32 +``` + + + ### `url` {#url} Represent a URL string as described by https://url.spec.whatwg.org/ diff --git a/packages/compiler/lib/lib.tsp b/packages/compiler/lib/lib.tsp index 50b7785392..a6ba028692 100644 --- a/packages/compiler/lib/lib.tsp +++ b/packages/compiler/lib/lib.tsp @@ -120,6 +120,14 @@ scalar duration; */ scalar boolean; +/** + * Represent a 32-bit unix timestamp datetime with 1s of granularity. + * It measures time by the number of seconds that have elapsed since 00:00:00 UTC on 1 January 1970. + * + */ +@encode("unixTimestamp", int32) +scalar unixTimestamp32 extends utcDateTime; + /** * Represent a model */