需求
-
使用Ubuntu Noble为仓颉编译Win环境的IANA TimeZone;
-
https://www.iana.org/time-zones
-
https://data.iana.org/time-zones/releases
-
https://bbs.huaweicloud.com/blogs/247561
-
华为编译方式会有问题,用R编写脚本编译
安装R
# apt-get update# apt install r-base -y# R --versionR version 4.3.3 (2024-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
编写R脚本
vim compile_iana_tz.r
# 下载并编译IANA time zone数据库,Win环境需额外依赖Cygwin
version_to_install <- "2024b"# Win环境:指向zic.exe,先决条件:已安装Cygwin,C:\\Cygwin\\usr\\sbin
zic_path <- "./"dir.create("./IanaRelease", showWarnings = FALSE)target_tar_file <- paste("./IanaRelease/tzdata",version_to_install,".tar.gz",sep="")target_untar <- paste("./IanaRelease/",version_to_install,sep="")target_compiled_version <- paste(target_untar,"/CompileArtifact",sep="")# 下载IANA Time Zone数据库,并复制到IanaRelease文件夹
download.file(paste("https://data.iana.org/time-zones/releases/tzdata",version_to_install,".tar.gz",sep=""),target_tar_file)# 解压并移动到有Iana的Release名称
untar(tarfile=target_tar_file, exdir=target_untar)# 添加zic到System Path
old_path <- Sys.getenv("PATH")
Sys.setenv(PATH = paste(old_path,zic_path, sep = ";"))# 编译:注:,"pacificnew","systemv"可能编译失败,此处移除
for (zone in c("etcetera", "southamerica","northamerica","europe","africa","antarctica","asia", "australasia", "backward")){print(paste("Compile",zone))system(paste("zic -d ",paste(target_compiled_version," ",target_untar,"/",zone,sep=""),sep=""))
}cat(version_to_install,file=paste(target_compiled_version,"/+VERSION",sep=""),append=FALSE)print(paste("IANA Time Zone Database",version_to_install,"installed in",gsub("\\./",paste0(getwd(),"/"),target_compiled_version)))# 测试
Sys.setenv(TZDIR=target_compiled_version)
attr(OlsonNames(),"Version")
运行R脚本
# Rscript compile_iana_tz.r试开URL'https://data.iana.org/time-zones/releases/tzdata2024b.tar.gz'
Content type 'application/x-gzip' length 459393 bytes (448 KB)
==================================================
downloaded 448 KB[1] "Compile etcetera"
[1] "Compile southamerica"
[1] "Compile northamerica"
[1] "Compile europe"
[1] "Compile africa"
[1] "Compile antarctica"
[1] "Compile asia"
[1] "Compile australasia"
[1] "Compile backward"
[1] "IANA Time Zone Database 2024b installed in /elf/tzdir/IanaRelease/2024b/CompileArtifact"
[1] "2024b"
配置环境
-
将/elf/tzdir/IanaRelease/2024b/CompileArtifact
目录下文件下载,并放置到D:\Install\FreeDev\Tzdb2024b; -
配置环境变量:CJ_TZPATH = D:\Install\FreeDev\Tzdb2024b;
-
重启计算机;
时区案例
import std.time.DateTime
import std.time.TimeZonemain() {let dateTime = DateTime.now(timeZone: TimeZone.load("Asia/Shanghai"))println("CST: ${dateTime}")println("UTC: ${dateTime.inUTC()}")println("EDT: ${dateTime.inTimeZone(TimeZone.load("America/New_York"))}")
}
cjpm runCST: 2024-11-01T12:47:46.9951878+08:00
UTC: 2024-11-01T04:47:46.9951878Z
EDT: 2024-11-01T00:47:46.9951878-04:00cjpm run finished
卸载R
apt remove r-base -yrm -rf tzdir