2024年12月17日 星期二

Node.js 開發筆記 - 使用 Electron + Vite + Vue 開發一款 PC app ,可支援 mDNS 裝置搜尋 @ macOS 15.2



有點久沒用 Electron 開發 PC app ,協助同事從旁實驗一下新的架構,這次研究後,直接用 electron-vite 初始化專案,核心就是 Electron + Vite 的研發環境,前台是 Vue 前端畫面。原先在想是不是一律自行安裝套件且故意都裝最新版,想完後還是縮一下,回歸別人整理好的工具,而這次強調用 Vite 整合,就不從 electron-vue 開始。

開發環境:

% sw_vers 
ProductName: macOS
ProductVersion: 15.2
BuildVersion: 24C101
% nvm use --lts         
Now using node v22.12.0 (npm v10.9.0)

流水帳:

```
% npm create electron-vite@latest
Need to install the following packages:
create-electron-vite@0.7.1
Ok to proceed? (y) y


> npx
> create-electron-vite

✔ Project name: … my-electron-app
✔ Project template: › Vue

Scaffolding project in /private/tmp/my-electron-app...

Done. Now run:

  cd my-electron-app
  npm install
  npm run dev

npm notice
npm notice New major version of npm available! 10.9.0 -> 11.0.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v11.0.0
npm notice To update run: npm install -g npm@11.0.0
npm notice

% cd my-electron-app
my-electron-app % npm install express multicast-dns axios
my-electron-app % cat package.json 
{
  "name": "my-electron-app",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "vue-tsc && vite build && electron-builder",
    "preview": "vite preview"
  },
  "dependencies": {
    "axios": "^1.7.9",
    "express": "^4.21.2",
    "multicast-dns": "^7.2.5",
    "vue": "^3.4.21"
  },
  "devDependencies": {
    "@vitejs/plugin-vue": "^5.0.4",
    "electron": "^30.0.1",
    "electron-builder": "^24.13.3",
    "typescript": "^5.2.2",
    "vite": "^5.1.6",
    "vite-plugin-electron": "^0.28.6",
    "vite-plugin-electron-renderer": "^0.14.5",
    "vue-tsc": "^2.0.26"
  },
  "main": "dist-electron/main.js"
}
my-electron-app % npm run dev
```

如此就有了一個畫面,而目錄結構:

```
% tree -I 'node_modules|dist|build'
.
├── README.md
├── dist-electron
│   ├── main.js
│   └── preload.mjs
├── electron
│   ├── electron-env.d.ts
│   ├── main.ts
│   └── preload.ts
├── electron-builder.json5
├── index.html
├── package-lock.json
├── package.json
├── public
│   ├── electron-vite.animate.svg
│   ├── electron-vite.svg
│   └── vite.svg
├── src
│   ├── App.vue
│   ├── assets
│   │   └── vue.svg
│   ├── components
│   │   └── HelloWorld.vue
│   ├── main.ts
│   ├── style.css
│   └── vite-env.d.ts
├── tsconfig.json
├── tsconfig.node.json
└── vite.config.ts

7 directories, 22 files
```

接著,要來擴充一下功能,讓這支程式可以使用 mDNS 協定偵測環境,這功能需實作在 Electron 架構上,在 main.ts 添加裝置搜尋:

```
$ cat electron/main.ts 
...

import mdns from 'multicast-dns'

...

// 使用一個全域變數紀錄偵測到的 mDNS 裝置,並記錄他初次出現的時間,也紀錄最後一次看到的時間
const mdnsDevices: { [key: string]: { name: string, type: string, firstSeen: number, lastSeen: number, data: any[], answers: any[] } } = {}

function startMdnsQuery() {
  const mdnsInstance = mdns()

  console.log('mDNS Query Start...')

  // 修改 name & type
  // dns-sd -B _services._dns-sd._udp local
  mdnsInstance.query({
    questions: [{
      //name: '_http._tcp.local',
      name: '_services._dns-sd._udp.local',
      type: 'PTR'
    }]
  })

  mdnsInstance.on('response', (response: { answers: string | any[] }) => {
    console.log('mDNS Response:', response)

    if (win && response.answers.length > 0) {
      for (const answer of response.answers) {
        try {
          // 建立一個 unique key 來代表一個裝置
          const key = `${answer.name}-${answer.type}`
          if (!mdnsDevices[key]) {
            mdnsDevices[key] = {
              name: answer.name,
              type: answer.type,
              data: [answer.data],
              firstSeen: Date.now(),
              lastSeen: Date.now(),
              answers: [answer]
            }
            console.log('ADD Device:')
            console.log(mdnsDevices[key])
          } else {
            mdnsDevices[key].lastSeen = Date.now()
            mdnsDevices[key].answers.push(answer)
            if (!mdnsDevices[key].data.includes(answer.data)) {
              mdnsDevices[key].data.push(answer.data)
            }
          }
          win.webContents.send('mdns-found', mdnsDevices)
        } catch (error) {
          console.error(error)
        }
      }
    }
  })
}
...

app.whenReady().then(() => {
  createWindow()
  startMdnsQuery()
})
```

在 preload.ts 增加資料回傳到前端網頁上:

```
$ cat electron/preload.ts 
...
contextBridge.exposeInMainWorld('mdnsAPI', {
  onFound: (callback: (devices: any[]) => void) => {
    ipcRenderer.on('mdns-found', (_event, devices) => {
      callback(devices)
    })
  }
})
```

App.vue:

```
<script setup lang="ts">
import HelloWorld from './components/HelloWorld.vue'

import { ref, onMounted } from 'vue'

const devices = ref<any[]>([])
onMounted(() => {
  // 若在 preload 中已暴露 mdnsAPI
  if (window.mdnsAPI && typeof window.mdnsAPI.onFound === 'function') {
    window.mdnsAPI.onFound((foundDevices) => {
      // 將接收到的裝置資料放入響應式變數
      devices.value = foundDevices
      console.log('Found devices:')
      console.log(foundDevices)
    })
  }
})
</script>

<template>
  <div>
    <a href="https://electron-vite.github.io" target="_blank">
      <img src="/electron-vite.svg" class="logo" alt="Vite logo" />
    </a>
    <a href="https://vuejs.org/" target="_blank">
      <img src="./assets/vue.svg" class="logo vue" alt="Vue logo" />
    </a>
  </div>
  <!--
  <HelloWorld msg="Vite + Vue" />
  <hr />
  -->
  <div>
    <h3>已搜尋到的裝置:</h3>
    <ul id="deviceList">
      <li v-for="(device, index) in devices" :key="index">
        [{{ new Date(device.firstSeen).toLocaleString('zh-TW', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit' }) }}] {{ device.name }} ({{ device.type }}) 
        <ul>
          <li v-for="(data, i) in device.data" :key="I">
            {{ data }}
          </li>
        </ul>
      </li>
    </ul>
  </div>
</template>

<style scoped>
.logo {
  height: 6em;
  padding: 1.5em;
  will-change: filter;
  transition: filter 300ms;
}
.logo:hover {
  filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.vue:hover {
  filter: drop-shadow(0 0 2em #42b883aa);
}

#deviceList {
  text-align: left;
  list-style-type: none;
  padding: 0;
}
</style>
```

收工 ,有空再來做些什麼應用吧:github.com/changyy/study-my-electron-app

2024年12月5日 星期四

PHP 開發筆記 - 產生 CountryCode, CountryName, CityName, GeoLocation 列表

原本一直盧 AI 產出,發現產出的品質很難控,最後就轉個彎去把 GeoIP DB 內的資料輸出即可,而策略也很簡單,單純用 IP 暴力輪詢。理論上可以優雅一點去了解 DB Record format,總之,暴力解也很快,就順手先記錄一下,此例僅列出部分資訊(非輪詢所有 IPv4):

```
<?php
if (!extension_loaded('geoip')) {
    die("GeoIP extension is not installed\n");
}

class GeoIPParser {
    private $dbPath;
    
    public function __construct($dbPath = '/tmp/db.dat') {
        $this->dbPath = $dbPath;
        geoip_setup_custom_directory('/tmp');
    }
    
    public function parse() {
        if (!file_exists($this->dbPath)) {
            throw new Exception("GeoIP City database not found at {$this->dbPath}");
        }
        
        $locations = [];
        $processed = [];
        
        try {
            // 遍歷 IP 範圍,每個 /16 subnet 取樣幾個 IP
            for ($first = 1; $first <= 255; $first++) {
                fprintf(STDERR, "\rProcessing IP block: %d/255", $first);
                
                for ($second = 0; $second <= 255; $second += 5) {
                    $ip = "$first.$second.1.1";
                    $record = geoip_record_by_name($ip);
                    
                    if ($record && 
                        !empty($record['country_code']) && 
                        !empty($record['city'])) {
                        
                        $key = $record['country_code'] . '|' . $record['city'];
                        
                        if (!isset($processed[$key])) {
                            $location = [
                                'country_code' => $record['country_code'],
                                'country_name' => $record['country_name'],
                                'city_name' => $record['city'],
                                'geo_location' => [
                                    'latitude' => round($record['latitude'], 4),
                                    'longitude' => round($record['longitude'], 4)
                                ]
                            ];
                            
                            $locations[] = $location;
                            $processed[$key] = true;
                        }
                    }
                }
            }
            
            fprintf(STDERR, "\nProcessing completed. Total locations found: " . count($locations) . "\n");
            
            // 按國家代碼和城市名稱排序
            usort($locations, function($a, $b) {
                $countryComp = strcmp($a['country_code'], $b['country_code']);
                return $countryComp === 0 ? 
                    strcmp($a['city_name'], $b['city_name']) : 
                    $countryComp;
            });
            
            return $locations;
        } catch (Exception $e) {
            fprintf(STDERR, "Error during processing: " . $e->getMessage() . "\n");
            throw $e;
        }
    }
}

try {
    $parser = new GeoIPParser();
    $locations = $parser->parse();
    
    // 輸出為格式化的 JSON
    echo json_encode($locations, 
        JSON_PRETTY_PRINT | 
        JSON_UNESCAPED_UNICODE | 
        JSON_UNESCAPED_SLASHES
    );
    
} catch (Exception $e) {
    fwrite(STDERR, "Error: " . $e->getMessage() . "\n");
    exit(1);
}
```

產出:

```
% php83 -ini | grep geoip
/opt/local/var/db/php83/geoip.ini,
geoip
geoip support => enabled
geoip extension version => 1.1.1
geoip library version => 1005000
geoip.custom_directory => no value => no value
% php83 geo-lookup.php 
Processing IP block: 255/255
Processing completed. Total locations found: 2657
...
```

片段資料: 

% php83 list-geo-city.php | jq '[.[]|select(.country_code=="TW")]'         
Processing IP block: 255/255
Processing completed. Total locations found: 8020
[
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Anping District",
    "geo_location": {
      "latitude": 22.9965,
      "longitude": 120.1617
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Bade District",
    "geo_location": {
      "latitude": 24.9259,
      "longitude": 121.2763
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Banqiao",
    "geo_location": {
      "latitude": 25.0104,
      "longitude": 121.4683
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Beitou",
    "geo_location": {
      "latitude": 25.1403,
      "longitude": 121.4948
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Chang-hua",
    "geo_location": {
      "latitude": 24.0759,
      "longitude": 120.5657
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Chiayi City",
    "geo_location": {
      "latitude": 23.4815,
      "longitude": 120.4498
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Chiyayi County",
    "geo_location": {
      "latitude": 23.4461,
      "longitude": 120.5728
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Daan",
    "geo_location": {
      "latitude": 25.0316,
      "longitude": 121.5345
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Dacun",
    "geo_location": {
      "latitude": 23.9978,
      "longitude": 120.547
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Dawan",
    "geo_location": {
      "latitude": 23.2073,
      "longitude": 120.1906
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Daya",
    "geo_location": {
      "latitude": 24.2226,
      "longitude": 120.6493
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Douliu",
    "geo_location": {
      "latitude": 23.7125,
      "longitude": 120.545
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "East District",
    "geo_location": {
      "latitude": 22.9721,
      "longitude": 120.2224
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Guishan",
    "geo_location": {
      "latitude": 25.0273,
      "longitude": 121.359
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Hsinchu",
    "geo_location": {
      "latitude": 24.8065,
      "longitude": 120.9706
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Hsinchu County",
    "geo_location": {
      "latitude": 24.673,
      "longitude": 121.1614
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Hualien City",
    "geo_location": {
      "latitude": 23.9807,
      "longitude": 121.6115
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Jian",
    "geo_location": {
      "latitude": 23.9516,
      "longitude": 121.5639
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Jinshan",
    "geo_location": {
      "latitude": 25.0613,
      "longitude": 121.5705
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Kaohsiung City",
    "geo_location": {
      "latitude": 22.6148,
      "longitude": 120.3139
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Keelung",
    "geo_location": {
      "latitude": 25.1322,
      "longitude": 121.742
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Linkou District",
    "geo_location": {
      "latitude": 25.0738,
      "longitude": 121.3935
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Miaoli",
    "geo_location": {
      "latitude": 24.5641,
      "longitude": 120.8275
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Nantou City",
    "geo_location": {
      "latitude": 23.9082,
      "longitude": 120.6558
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Neihu District",
    "geo_location": {
      "latitude": 25.0811,
      "longitude": 121.5838
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "New Taipei City",
    "geo_location": {
      "latitude": 24.9466,
      "longitude": 121.586
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Penghu County",
    "geo_location": {
      "latitude": 23.5748,
      "longitude": 119.6098
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Pingtung City",
    "geo_location": {
      "latitude": 22.6745,
      "longitude": 120.491
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Puli",
    "geo_location": {
      "latitude": 23.9678,
      "longitude": 120.9644
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Sanchong District",
    "geo_location": {
      "latitude": 25.0691,
      "longitude": 121.4878
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Sanxia District",
    "geo_location": {
      "latitude": 24.9336,
      "longitude": 121.372
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Shiding District",
    "geo_location": {
      "latitude": 24.9956,
      "longitude": 121.6546
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Shoufeng",
    "geo_location": {
      "latitude": 23.8341,
      "longitude": 121.521
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Taibao",
    "geo_location": {
      "latitude": 23.4603,
      "longitude": 120.3284
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Taichung",
    "geo_location": {
      "latitude": 24.144,
      "longitude": 120.6844
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Taichung City",
    "geo_location": {
      "latitude": 24.1547,
      "longitude": 120.6716
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Tainan City",
    "geo_location": {
      "latitude": 22.9917,
      "longitude": 120.2147
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Taipei",
    "geo_location": {
      "latitude": 25.0504,
      "longitude": 121.5324
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Taitung",
    "geo_location": {
      "latitude": 22.7563,
      "longitude": 121.1418
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Taoyuan",
    "geo_location": {
      "latitude": 24.9977,
      "longitude": 121.2965
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Taoyuan District",
    "geo_location": {
      "latitude": 24.9889,
      "longitude": 121.3175
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Xizhi District",
    "geo_location": {
      "latitude": 25.0696,
      "longitude": 121.6577
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Yilan",
    "geo_location": {
      "latitude": 24.7574,
      "longitude": 121.7421
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Yongkang District",
    "geo_location": {
      "latitude": 23.0204,
      "longitude": 120.2591
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Yunlin",
    "geo_location": {
      "latitude": 23.7113,
      "longitude": 120.3897
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Zhongli District",
    "geo_location": {
      "latitude": 24.9614,
      "longitude": 121.2437
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Zhubei",
    "geo_location": {
      "latitude": 24.8351,
      "longitude": 121.0056
    }
  },
  {
    "country_code": "TW",
    "country_name": "Taiwan",
    "city_name": "Zuoying",
    "geo_location": {
      "latitude": 22.6868,
      "longitude": 120.2971
    }
  }
]

2024年12月4日 星期三

PHP 開發筆記 - 關於 DST 日光節約時間的判斷邏輯與實現方式

這是一個很古老的議題,但因為產品要進行本地化資訊顯示開始提供一些架構,然而,這本身顯示時間上都已經很成熟也有內建 library 可用,但基於一些嵌入式產品的條件,如連網狀態等,需要復刻一版服務出來,像是把日光節約時間的邏輯給列出來等。

輕鬆問問 Claude.AI 就立馬有了一版,且過程中還發現 AI 採用每日檢查是否是日光節約時間 XD 但明明可以查 tzdata 有效率做完這件事才對。就順手引導 AI ,自己也下去改一下判斷邏輯。

此外,也透過 AI 補足了一些知識,像是 tzdata 會定期更新,且一年也可能更新數次:


隨便下載一份解開來看:
  • zone.tab: 全部時區清單,內有 geo location 資訊
  • northamerica: 北美洲的 DST 規則
  • europe: 歐洲的 DST 規則
  • asia: 亞洲的 DST 規則
  • australasia: 澳洲和亞洲部分地區的 DST 規則
  • africa: 非洲的 DST 規則
  • southamerica: 南美洲的 DST 規則
  • antarctica: 南極洲的 DST 規則
而 abbreviation 縮寫意義:
  • EST = Eastern Standard Time (東部標準時間)
  • EDT = Eastern Daylight Time (東部夏令時間)
  • PST = Pacific Standard Time (太平洋標準時間)
  • PDT = Pacific Daylight Time (太平洋夏令時間)
  • CST = Central Standard Time (中部標準時間)
  • CDT = Central Daylight Time (中部夏令時間)
最後,用 PHP Code 順一個出來,這邊 dst_begin 不是日光節約時間真正的起始日,僅是一個趨近資料,只有當該時區不是日光節約時間時,才會是下一個日光節約時段開始的時間

```
<?php
$output = [];

$dst_query_start = strtotime("-7 day midnight");
$days_in_year = date('L') ? 366 + 7 : 365 + 7; // 檢查是否為閏年
$dst_query_end = $dst_query_start + (86400 * $days_in_year);
try {
foreach(DateTimeZone::listIdentifiers() as $tz) {
$datetime = new DateTime('now', new DateTimeZone($tz));
$timezone = new DateTimeZone($tz);
$location = $timezone->getLocation();

$transitions = $timezone->getTransitions($dst_query_start, $dst_query_end);

$has_dst = false;
$dst_begin = array( 'datetime' => NULL, 'timestamp' => NULL, 'offset' => NULL, 'abbreviation' => NULL);
$dst_end = array( 'datetime' => NULL, 'timestamp' => NULL, 'offset' => NULL, 'abbreviation' => NULL);

for ($i=0, $cnt=count($transitions) ; $i < $cnt ; ++$i ) {
if ($has_dst == false) {
if ($transitions[$i]['isdst']) {
$has_dst = true;
$dst_begin = array(
'datetime' => date('Y-m-d H:i:s', $transitions[$i]['ts']),
'timestamp' => $transitions[$i]['ts'],
'offset' => $transitions[$i]['offset'],
'abbreviation' => $transitions[$i]['abbr'],
);
}
} else if (!$transitions[$i]['isdst']) {
$dst_end = array(
'datetime' => date('Y-m-d H:i:s', $transitions[$i]['ts']),
'timestamp' => $transitions[$i]['ts'],
'offset' => $transitions[$i]['offset'],
'abbreviation' => $transitions[$i]['abbr'],
);
break;
}
}

array_push($output, array(
'timezone' => $tz,
'offset' => $datetime->format('P'),
'abbreviation' => $datetime->format('T'),
'is_dst' => (bool)$datetime->format('I'),
'dst_info' => array(
'begin' => $dst_begin,
'end' => $dst_end,
'has_dst' => $has_dst,
),
'country_code' => isset($location['country_code']) && $location['country_code'] != '??' ? $location['country_code'] : null,
'latitude' => isset($location['latitude']) ? $location['latitude'] : null,
'longitude' => isset($location['longitude']) ? $location['longitude']: null,
));
}
} catch (Exception $e) {
$output = $e->getMessage();
}
echo json_encode($output, JSON_PRETTY_PRINT)."\n";
```

在此刻 2024-12-04 運行 PHP Code 結果,透過 jq 來過濾清單,列出哪些有日光節約時段時區:

```
% php83 test.php | jq '[.[] | select(.dst_info.has_dst == true) | {timezone: .timezone, dst_begin: .dst_info.begin.datetime, dst_end: .dst_info.end.datetime}]'
[
  {
    "timezone": "Africa/Cairo",
    "dst_begin": "2025-04-24 22:00:00",
    "dst_end": "2025-10-30 21:00:00"
  },
  {
    "timezone": "Africa/Casablanca",
    "dst_begin": "2025-02-23 02:00:00",
    "dst_end": "2025-04-06 02:00:00"
  },
  {
    "timezone": "Africa/Ceuta",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Africa/El_Aaiun",
    "dst_begin": "2025-02-23 02:00:00",
    "dst_end": "2025-04-06 02:00:00"
  },
  {
    "timezone": "America/Adak",
    "dst_begin": "2025-03-09 12:00:00",
    "dst_end": "2025-11-02 11:00:00"
  },
  {
    "timezone": "America/Anchorage",
    "dst_begin": "2025-03-09 11:00:00",
    "dst_end": "2025-11-02 10:00:00"
  },
  {
    "timezone": "America/Asuncion",
    "dst_begin": "2024-11-27 00:00:00",
    "dst_end": "2025-03-23 03:00:00"
  },
  {
    "timezone": "America/Boise",
    "dst_begin": "2025-03-09 09:00:00",
    "dst_end": "2025-11-02 08:00:00"
  },
  {
    "timezone": "America/Cambridge_Bay",
    "dst_begin": "2025-03-09 09:00:00",
    "dst_end": "2025-11-02 08:00:00"
  },
  {
    "timezone": "America/Chicago",
    "dst_begin": "2025-03-09 08:00:00",
    "dst_end": "2025-11-02 07:00:00"
  },
  {
    "timezone": "America/Ciudad_Juarez",
    "dst_begin": "2025-03-09 09:00:00",
    "dst_end": "2025-11-02 08:00:00"
  },
  {
    "timezone": "America/Denver",
    "dst_begin": "2025-03-09 09:00:00",
    "dst_end": "2025-11-02 08:00:00"
  },
  {
    "timezone": "America/Detroit",
    "dst_begin": "2025-03-09 07:00:00",
    "dst_end": "2025-11-02 06:00:00"
  },
  {
    "timezone": "America/Edmonton",
    "dst_begin": "2025-03-09 09:00:00",
    "dst_end": "2025-11-02 08:00:00"
  },
  {
    "timezone": "America/Glace_Bay",
    "dst_begin": "2025-03-09 06:00:00",
    "dst_end": "2025-11-02 05:00:00"
  },
  {
    "timezone": "America/Goose_Bay",
    "dst_begin": "2025-03-09 06:00:00",
    "dst_end": "2025-11-02 05:00:00"
  },
  {
    "timezone": "America/Grand_Turk",
    "dst_begin": "2025-03-09 07:00:00",
    "dst_end": "2025-11-02 06:00:00"
  },
  {
    "timezone": "America/Halifax",
    "dst_begin": "2025-03-09 06:00:00",
    "dst_end": "2025-11-02 05:00:00"
  },
  {
    "timezone": "America/Havana",
    "dst_begin": "2025-03-09 05:00:00",
    "dst_end": "2025-11-02 05:00:00"
  },
  {
    "timezone": "America/Indiana/Indianapolis",
    "dst_begin": "2025-03-09 07:00:00",
    "dst_end": "2025-11-02 06:00:00"
  },
  {
    "timezone": "America/Indiana/Knox",
    "dst_begin": "2025-03-09 08:00:00",
    "dst_end": "2025-11-02 07:00:00"
  },
  {
    "timezone": "America/Indiana/Marengo",
    "dst_begin": "2025-03-09 07:00:00",
    "dst_end": "2025-11-02 06:00:00"
  },
  {
    "timezone": "America/Indiana/Petersburg",
    "dst_begin": "2025-03-09 07:00:00",
    "dst_end": "2025-11-02 06:00:00"
  },
  {
    "timezone": "America/Indiana/Tell_City",
    "dst_begin": "2025-03-09 08:00:00",
    "dst_end": "2025-11-02 07:00:00"
  },
  {
    "timezone": "America/Indiana/Vevay",
    "dst_begin": "2025-03-09 07:00:00",
    "dst_end": "2025-11-02 06:00:00"
  },
  {
    "timezone": "America/Indiana/Vincennes",
    "dst_begin": "2025-03-09 07:00:00",
    "dst_end": "2025-11-02 06:00:00"
  },
  {
    "timezone": "America/Indiana/Winamac",
    "dst_begin": "2025-03-09 07:00:00",
    "dst_end": "2025-11-02 06:00:00"
  },
  {
    "timezone": "America/Inuvik",
    "dst_begin": "2025-03-09 09:00:00",
    "dst_end": "2025-11-02 08:00:00"
  },
  {
    "timezone": "America/Iqaluit",
    "dst_begin": "2025-03-09 07:00:00",
    "dst_end": "2025-11-02 06:00:00"
  },
  {
    "timezone": "America/Juneau",
    "dst_begin": "2025-03-09 11:00:00",
    "dst_end": "2025-11-02 10:00:00"
  },
  {
    "timezone": "America/Kentucky/Louisville",
    "dst_begin": "2025-03-09 07:00:00",
    "dst_end": "2025-11-02 06:00:00"
  },
  {
    "timezone": "America/Kentucky/Monticello",
    "dst_begin": "2025-03-09 07:00:00",
    "dst_end": "2025-11-02 06:00:00"
  },
  {
    "timezone": "America/Los_Angeles",
    "dst_begin": "2025-03-09 10:00:00",
    "dst_end": "2025-11-02 09:00:00"
  },
  {
    "timezone": "America/Matamoros",
    "dst_begin": "2025-03-09 08:00:00",
    "dst_end": "2025-11-02 07:00:00"
  },
  {
    "timezone": "America/Menominee",
    "dst_begin": "2025-03-09 08:00:00",
    "dst_end": "2025-11-02 07:00:00"
  },
  {
    "timezone": "America/Metlakatla",
    "dst_begin": "2025-03-09 11:00:00",
    "dst_end": "2025-11-02 10:00:00"
  },
  {
    "timezone": "America/Miquelon",
    "dst_begin": "2025-03-09 05:00:00",
    "dst_end": "2025-11-02 04:00:00"
  },
  {
    "timezone": "America/Moncton",
    "dst_begin": "2025-03-09 06:00:00",
    "dst_end": "2025-11-02 05:00:00"
  },
  {
    "timezone": "America/Nassau",
    "dst_begin": "2025-03-09 07:00:00",
    "dst_end": "2025-11-02 06:00:00"
  },
  {
    "timezone": "America/New_York",
    "dst_begin": "2025-03-09 07:00:00",
    "dst_end": "2025-11-02 06:00:00"
  },
  {
    "timezone": "America/Nome",
    "dst_begin": "2025-03-09 11:00:00",
    "dst_end": "2025-11-02 10:00:00"
  },
  {
    "timezone": "America/North_Dakota/Beulah",
    "dst_begin": "2025-03-09 08:00:00",
    "dst_end": "2025-11-02 07:00:00"
  },
  {
    "timezone": "America/North_Dakota/Center",
    "dst_begin": "2025-03-09 08:00:00",
    "dst_end": "2025-11-02 07:00:00"
  },
  {
    "timezone": "America/North_Dakota/New_Salem",
    "dst_begin": "2025-03-09 08:00:00",
    "dst_end": "2025-11-02 07:00:00"
  },
  {
    "timezone": "America/Nuuk",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "America/Ojinaga",
    "dst_begin": "2025-03-09 08:00:00",
    "dst_end": "2025-11-02 07:00:00"
  },
  {
    "timezone": "America/Port-au-Prince",
    "dst_begin": "2025-03-09 07:00:00",
    "dst_end": "2025-11-02 06:00:00"
  },
  {
    "timezone": "America/Rankin_Inlet",
    "dst_begin": "2025-03-09 08:00:00",
    "dst_end": "2025-11-02 07:00:00"
  },
  {
    "timezone": "America/Resolute",
    "dst_begin": "2025-03-09 08:00:00",
    "dst_end": "2025-11-02 07:00:00"
  },
  {
    "timezone": "America/Santiago",
    "dst_begin": "2024-11-27 00:00:00",
    "dst_end": "2025-04-06 03:00:00"
  },
  {
    "timezone": "America/Scoresbysund",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "America/Sitka",
    "dst_begin": "2025-03-09 11:00:00",
    "dst_end": "2025-11-02 10:00:00"
  },
  {
    "timezone": "America/St_Johns",
    "dst_begin": "2025-03-09 05:30:00",
    "dst_end": "2025-11-02 04:30:00"
  },
  {
    "timezone": "America/Thule",
    "dst_begin": "2025-03-09 06:00:00",
    "dst_end": "2025-11-02 05:00:00"
  },
  {
    "timezone": "America/Tijuana",
    "dst_begin": "2025-03-09 10:00:00",
    "dst_end": "2025-11-02 09:00:00"
  },
  {
    "timezone": "America/Toronto",
    "dst_begin": "2025-03-09 07:00:00",
    "dst_end": "2025-11-02 06:00:00"
  },
  {
    "timezone": "America/Vancouver",
    "dst_begin": "2025-03-09 10:00:00",
    "dst_end": "2025-11-02 09:00:00"
  },
  {
    "timezone": "America/Winnipeg",
    "dst_begin": "2025-03-09 08:00:00",
    "dst_end": "2025-11-02 07:00:00"
  },
  {
    "timezone": "America/Yakutat",
    "dst_begin": "2025-03-09 11:00:00",
    "dst_end": "2025-11-02 10:00:00"
  },
  {
    "timezone": "Antarctica/Macquarie",
    "dst_begin": "2024-11-27 00:00:00",
    "dst_end": "2025-04-05 16:00:00"
  },
  {
    "timezone": "Antarctica/McMurdo",
    "dst_begin": "2024-11-27 00:00:00",
    "dst_end": "2025-04-05 14:00:00"
  },
  {
    "timezone": "Antarctica/Troll",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Arctic/Longyearbyen",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Asia/Beirut",
    "dst_begin": "2025-03-29 22:00:00",
    "dst_end": "2025-10-25 21:00:00"
  },
  {
    "timezone": "Asia/Famagusta",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Asia/Gaza",
    "dst_begin": "2025-04-12 00:00:00",
    "dst_end": "2025-10-24 23:00:00"
  },
  {
    "timezone": "Asia/Hebron",
    "dst_begin": "2025-04-12 00:00:00",
    "dst_end": "2025-10-24 23:00:00"
  },
  {
    "timezone": "Asia/Jerusalem",
    "dst_begin": "2025-03-28 00:00:00",
    "dst_end": "2025-10-25 23:00:00"
  },
  {
    "timezone": "Asia/Nicosia",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Atlantic/Azores",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Atlantic/Bermuda",
    "dst_begin": "2025-03-09 06:00:00",
    "dst_end": "2025-11-02 05:00:00"
  },
  {
    "timezone": "Atlantic/Canary",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Atlantic/Faroe",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Atlantic/Madeira",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Australia/Adelaide",
    "dst_begin": "2024-11-27 00:00:00",
    "dst_end": "2025-04-05 16:30:00"
  },
  {
    "timezone": "Australia/Broken_Hill",
    "dst_begin": "2024-11-27 00:00:00",
    "dst_end": "2025-04-05 16:30:00"
  },
  {
    "timezone": "Australia/Hobart",
    "dst_begin": "2024-11-27 00:00:00",
    "dst_end": "2025-04-05 16:00:00"
  },
  {
    "timezone": "Australia/Lord_Howe",
    "dst_begin": "2024-11-27 00:00:00",
    "dst_end": "2025-04-05 15:00:00"
  },
  {
    "timezone": "Australia/Melbourne",
    "dst_begin": "2024-11-27 00:00:00",
    "dst_end": "2025-04-05 16:00:00"
  },
  {
    "timezone": "Australia/Sydney",
    "dst_begin": "2024-11-27 00:00:00",
    "dst_end": "2025-04-05 16:00:00"
  },
  {
    "timezone": "Europe/Amsterdam",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Andorra",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Athens",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Belgrade",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Berlin",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Bratislava",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Brussels",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Bucharest",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Budapest",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Busingen",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Chisinau",
    "dst_begin": "2025-03-30 00:00:00",
    "dst_end": "2025-10-26 00:00:00"
  },
  {
    "timezone": "Europe/Copenhagen",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Dublin",
    "dst_begin": "2024-11-27 00:00:00",
    "dst_end": "2025-03-30 01:00:00"
  },
  {
    "timezone": "Europe/Gibraltar",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Guernsey",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Helsinki",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Isle_of_Man",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Jersey",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Kyiv",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Lisbon",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Ljubljana",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/London",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Luxembourg",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Madrid",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Malta",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Mariehamn",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Monaco",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Oslo",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Paris",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Podgorica",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Prague",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Riga",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Rome",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/San_Marino",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Sarajevo",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Skopje",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Sofia",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Stockholm",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Tallinn",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Tirane",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Vaduz",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Vatican",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Vienna",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Vilnius",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Warsaw",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Zagreb",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Europe/Zurich",
    "dst_begin": "2025-03-30 01:00:00",
    "dst_end": "2025-10-26 01:00:00"
  },
  {
    "timezone": "Pacific/Auckland",
    "dst_begin": "2024-11-27 00:00:00",
    "dst_end": "2025-04-05 14:00:00"
  },
  {
    "timezone": "Pacific/Chatham",
    "dst_begin": "2024-11-27 00:00:00",
    "dst_end": "2025-04-05 14:00:00"
  },
  {
    "timezone": "Pacific/Easter",
    "dst_begin": "2024-11-27 00:00:00",
    "dst_end": "2025-04-06 03:00:00"
  },
  {
    "timezone": "Pacific/Norfolk",
    "dst_begin": "2024-11-27 00:00:00",
    "dst_end": "2025-04-05 15:00:00"
  }
]
```