概要説明

追加の time_zone フィールドを Date オブジェクトに追加しました ( IANA database の time zone value に基づいています)。開発者は time_zone フィールドを使って明示的に Date プロパティにタイムゾーンを設定できます。一度タイムゾーンが設定されてしまえば、ユーザはアプリにおいても同じタイムゾーンで値を見ることができます。このメソッドでタイムゾーンが設定された場合、 startend の値は UTC offset を持つことがありません。加えて、日付にタイムゾーンの情報が設定された場合、 startend は時間を持たない日付に設定することはできません (例えば "2020-12-08" のように).

startendUTC offset が設定されている場合、public API は time_zone を常に null として返却します。

検証

これまで API でタイムゾーン付きの Date オブジェクトは "2021-12-15T08:30+09:00" という形の文字列を生成していました。これの代わりにタイムゾーンが設定できるようになり、さらにアプリでもそのタイムゾーンで表示されるとのことなので、早速試してみます。文字列の代わりに time_zone を設定しています。このページの日付を書き換えています。

#!/bin/sh
curl <https://api.notion.com/v1/pages/26ce46c250b94ee2b5cd7ba0f438328d> \\
  -H 'Authorization: Bearer '"$NOTION_API_KEY"'' \\
  -H "Content-Type: application/json" \\
  -H "Notion-Version: 2021-08-16" \\
  -X PATCH \\
	--data '{
  "properties": {
    "日付": {
      "date": {
        "start": "2021-12-15 08:30",
        "time_zone": "Asia/Tokyo"
      }
    }
  }
}'

JSON の返り値はこんな感じです。確かに start にはタイムゾーン付きの文字列が返ってきていますね。

{
    "object": "page",
    "id": "26ce46c2-50b9-4ee2-b5cd-7ba0f438328d",
    "created_time": "2021-12-14T23:35:00.000Z",
    "last_edited_time": "2021-12-15T00:12:00.000Z",
    "cover": null,
    "icon": null,
    "parent": {
        "type": "database_id",
        "database_id": "c63c00ad-201d-4bed-82b0-18dfca9b6ba0"
    },
    "archived": false,
    "properties": {
        "開示?": {
            "id": "%3BfBx",
            "type": "checkbox",
            "checkbox": false
        },
        "日付": {
            "id": "%3CWbe",
            "type": "date",
            "date": {
                "start": "2021-12-15T08:30:00.000+09:00",
                "end": null,
                "time_zone": null
            }
        },
        "原題": {
            "id": "%3FMR%7D",
            "type": "rich_text",
            "rich_text": [
                {
                    "type": "text",
                    "text": {
                        "content": "Time zone support",
                        "link": null
                    },
                    "annotations": {
                        "bold": false,
                        "italic": false,
                        "strikethrough": false,
                        "underline": false,
                        "code": false,
                        "color": "default"
                    },
                    "plain_text": "Time zone support",
                    "href": null
                }
            ]
        },
        "Number": {
            "id": "ANbi",
            "type": "number",
            "number": 36
        },
        "URL": {
            "id": "o%3A~F",
            "type": "url",
            "url": "<https://developers.notion.com/changelog/time-zone-support>"
        },
        "タグ": {
            "id": "tUJV",
            "type": "multi_select",
            "multi_select": [
                {
                    "id": "fcb7bc23-a43d-4ff1-967f-db59a6125492",
                    "name": "ADDED",
                    "color": "green"
                }
            ]
        },
        "経過日数": {
            "id": "~Xof",
            "type": "formula",
            "formula": {
                "type": "number",
                "number": 0
            }
        },
        "名前": {
            "id": "title",
            "type": "title",
            "title": [
                {
                    "type": "text",
                    "text": {
                        "content": "Time zone のサポート",
                        "link": null
                    },
                    "annotations": {
                        "bold": false,
                        "italic": false,
                        "strikethrough": false,
                        "underline": false,
                        "code": false,
                        "color": "default"
                    },
                    "plain_text": "Time zone のサポート",
                    "href": null
                }
            ]
        }
    },
    "url": "<https://www.notion.so/Time-zone-26ce46c250b94ee2b5cd7ba0f438328d>"
}

このページの日付を見てみると確かに JST で表示されています。問題なさそうです。文字列生成しなくていいのは楽ですね。

現在私が配布している Notion Tools の Alfred workflow の場合には、 MY_TZ という環境変数に +09:00 というものを書いてもらっています。これができるようになったのなら、TIME_ZONE という部分に Asia/Tokyo を書いてもらうようにすればいいので、こっちの方が親切な気がしますね。バージョンアップした方がよさそうですね。


Notion API Changelog まとめ