2015-09-24 16 views
2

我想解析Unix系統上的tzfile(Olson)格式。在tzfile(5)手冊頁它規定如下:tzfile格式:處理istd和isgmt

Then there are tzh_ttisstdcnt standard/wall indicators, each stored 
as a one-byte value; they tell whether the transition times 
associated with local time types were specified as standard time or 
wall clock time, and are used when a timezone file is used in 
handling POSIX-style timezone environment variables. 

Finally, there are tzh_ttisgmtcnt UTC/local indicators, each stored 
as a one-byte value; they tell whether the transition times 
associated with local time types were specified as UTC or local time, 
and are used when a timezone file is used in handling POSIX-style 
timezone environment variables. 

這是否意味着我可以忽略isstd和isgmt,仍然可以得到正確的時間?在現場檢查中,這似乎是這種情況,但是在C源文件中進行挖掘時,我發現unix會根據這些值進行一些調整。

+0

儘管StackOverflow上的某個人可能能夠回答你的問題,但你會在[tz郵件列表](https://mm.icann.org/mailman/listinfo/tz)上得到更好的運氣,負責Olson tzdata和類Unix系統上使用的相關tzcode。如果你在那裏得到答案,你可以回到這裏回答你自己的問題。 –

回答

0

按照上面的要求,我在郵件列表中詢問。答案是查看代碼。所以相關的代碼在zic.c(區編譯器)和glib的tzfile.c。兩者的源代碼可以在github上找到。爲zic.c相關的代碼是

switch (lowerit(*ep)) { 
     case 's': /* Standard */ 
      rp->r_todisstd = true; 
      rp->r_todisgmt = false; 
      *ep = '\0'; 
      break; 
     case 'w': /* Wall */ 
      rp->r_todisstd = false; 
      rp->r_todisgmt = false; 
      *ep = '\0'; 
      break; 
     case 'g': /* Greenwich */ 
     case 'u': /* Universal */ 
     case 'z': /* Zulu */ 
      rp->r_todisstd = true; 
      rp->r_todisgmt = true; 
      *ep = '\0'; 
      break; 

哪個說,有3種可能情況:isstd = true && isgmt = false,既虛假和雙方真實。所以看到的是與這些標記完成,在tzfile.c相關的代碼是

if (trans_type->isgmt) 
    /* The transition time is in GMT. No correction to apply. */ ; 
else if (isdst && !trans_type->isstd) 
    /* The type says this transition is in "local wall clock time", and 
    wall clock time as of the previous transition was DST. Correct 
    for the difference between the rule's DST offset and the user's 
    DST offset. */ 
    transitions[i] += dstoff - rule_dstoff; 
else 
    /* This transition is in "local wall clock time", and wall clock 
    time as of this iteration is non-DST. Correct for the 
    difference between the rule's standard offset and the user's 
    standard offset. */ 
    transitions[i] += stdoff - rule_stdoff; 

因此,這似乎是說,如果isgmt是真實的,我們可以無視一切。如果它是假的,那麼如果前面的轉換是DST,並且當前的轉換不是標準的(即上面的情況'w',因爲它也不是gmt),應用dst偏移量(在文件中找到的最後一個偏移量)。否則應用標準偏移量。

這似乎意味着glibc會忽略單個tt_types和case's中的偏移量。我在tz包中查找localtime.c,它的工作方式相同。

我只能從這一切中得出結論,tzfile中的大部分信息並未在任何地方實際使用。其中一些可能是由於POSIX的要求。如果任何人可以擴展下面的細節,請做。除了C源代碼之外,將這種行爲記錄在互聯網上的某個地方會很好。