最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【未解决】Vanilla的bbs系统中,帖子的发布时间,显示不正常

BBS crifan 2190浏览 0评论

【问题】

vanilla的bbs系统中,管理后台中看到的帖子的发布时间,是正常的:

time is ok

但是退出登录后,看到的时间,却是不正常的:

time is abnormal

对应的应该是2:22 pm=14:22,但是此处却显示出是12:22

【解决过程】

1.去后台管理界面中找了下,貌似和时间有关的设置,只有一个locale:

locale en-CA

当前的是en-CA,可能就是因为不是当前的zh-CN,所以才导致时间显示异常的吧。

2. 而关于locale,相关官网资料:

http://vanillaforums.org/docs/Localization

中,也没有找到确切的解释,是否和时间显示有关系。

3.后来在vanilla官网中的

http://vanillaforums.org/addon/browse/locales

看到有中文的翻译:

http://vanillaforums.org/addon/vf_zh_cn-locale

所以,有空可以试试,下载并安装,看看效果如何,是否能解决时间显示异常的问题。

4.后来看到有多个版本的中文翻译:

http://vanillaforums.org/addon/vf_zh_cn-locale

http://vanillaforums.org/addon/zh_cn-locale

http://vanillaforums.org/addon/chinese-locale

最后打算先去试试:

http://vanillaforums.org/addon/zh_cn-locale

下载对应文件:zh_cn-locale-1-2-1.zip

通过Cpanel上传上去并解压,得到zh-CN文件夹:

zh_CN-dir2

再去vanilla后台设置locale为zh-CN:

set-locale-to-zh-CN2

后来发现,先要对于那个locale点击Enable去启用,然后才能设置为zh-CN:

enabled-zh-CN2

然后再退出登陆,去查看那个帖子的发布时间:

time-become-to-002

很明显,时间还是不对。

5.然后根据

http://vanillaforums.org/addon/zh_cn-locale

中的提示,貌似还需要手动改配置文件,就去找到:

bbs_root_dir/conf/config.php

结果发现此时已经配置好了,已经是zh-CN了:

conf-config-php-has-already-zh-CN2

所以无须再改。

6.不过,倒是发现一个现象:

en-CA对应时间是:12:22

zh-CN对应时间为:00:22

正好和en-CA与zh-CN的时区差距的12小时,所吻合。

所以,至少证明此处设置locale,是决定了时间显示的。

但是为何此处只显示出来的是00:22而不是2:22PM呢。

7.看来,还是需要找到具体的代码,才知道为何出错的。

8.后来倒是从zh-CN翻译文件中,找到相关代码了:

zh_CN\captured.php

$Definition['Dashboard'] = '控制台';
$Definition['Date.DefaultDayFormat'] = '%b %e 日';
$Definition['Date.DefaultFormat'] = '%Y %b %e日';
$Definition['Date.DefaultTimeFormat'] = '%H:%M';
$Definition['Date.DefaultYearFormat'] = '%B %Y';

其中相关的,应该是

$Definition[‘Date.DefaultTimeFormat’] = ‘%H:%M’;

所以,还是需要找到vanilla的代码才可以的。

所以再去下载了vanilla源码:vanilla-core-2-0-18-4.zip,然后去分析看看。

找了半天,终于找到上述中的DefaultTimeFormat被调用的一个地方了:

vanilla\library\core\class.format.php

      if ($Format == '') {
         // If the timestamp was during the current day
         if (date('Y m d', $Timestamp) == date('Y m d', $Now)) {
            // Use the time format
            $Format = T('Date.DefaultTimeFormat', '%l:%M%p');
         } else if (date('Y', $Timestamp) == date('Y', $Now)) {
            // If the timestamp is the same year, show the month and date
            $Format = T('Date.DefaultDayFormat', '%B %e');
         } else if (date('Y', $Timestamp) != date('Y', $Now)) {
            // If the timestamp is not the same year, just show the year
            $Format = T('Date.DefaultYearFormat', '%B %Y');
         } else {
            // Otherwise, use the date format
            $Format = T('Date.DefaultFormat', '%B %e, %Y');
         }
      }

      $FullFormat = T('Date.DefaultDateTimeFormat', '%c');

不过,还是没啥用。还是需要找到从哪里产生此处的时间的才行。

不过看了看代码,貌似class.format.php中的ToTimestamp是直接使用mktime生成时间的。

然后对于时间的格式化,zh-CN中可以找到

zh_cn-locale-1-2-1\zh_CN\captured_admin.php

中是:

$Definition[‘Date.DefaultDayFormat’] = ‘%B %e’;

$Definition[‘Date.DefaultTimeFormat’] = ‘%l:%M%p’;

而\zh_cn-locale-1-2-1\zh_CN\captured.php

中的是

$Definition[‘Date.DefaultFormat’] = ‘%Y %b %e日’;

$Definition[‘Date.DefaultTimeFormat’] = ‘%H:%M’;

所以,打算搞清楚%l参数的含义。

最后好不容易找到这里:

http://www.drupaluser.org/php_manual/function.strftime.html

的解释:

mysql> SELECT TIME_FORMAT('14:35:00', '%l:%i %p');

Or try '%l' in PHP, it works on most systems and is part of the Open Group specification of strftime().

所以,先去试试,添加一个%l 看看会有什么效果。

就去把locales/zh_CN/captured.php

改为

$Definition[‘Date.DefaultTimeFormat’] = ‘%l %H:%M’;

然后结果是

登陆时,显示的效果:

added-pref-time-login2

未登陆时的效果:

added-pref-time-logout2

总之,还是不对,只是添加了个前缀,而且%l的值,间好像只是当前的hour的值。

算是符合了:

http://www.fangyuqiang.com/archives/881

中的解释:

MySQL

Specifier Description

%l      Hour (1..12)

9. 不过,感觉此处方向搞错了。

正确的应该是上述:

http://www.drupaluser.org/php_manual/function.strftime.html

中所看到的:

strftime — 根据区域设置格式化本地时间/日期

说明

string strftime ( string $format [, int $timestamp ] )

返回用给定的格式字串对给出的 timestamp 进行格式输出后的字符串。如果没有给出时间戳则用当前的本地时间。月份和星期几以及其它和语言有关的字符串写法和用 setlocale() 设定的当前的区域有关。

感觉具体的时间和市区差别,应该是用setlocale决定的。

而决定了时间之后,如何显示,才是调用strftime去显示。

所以,想到应该是,设置locale为zh-CN,点击save那一刻,会去执行类似的setlocale才对。

然后也找到了locale相关的文件:

vanilla-core-2-0-18-4\vanilla\library\core\class.locale.php

但是还是没有完全看懂。

10.又去网上找了半天,后来通过google搜:

vanilla display time incorrect

竟然找到有人遇到类似的问题了:

http://vanillaforums.org/discussion/10458/time-zone-incorrect

参考其办法,去把根目录下的:

bootstrap.php

中,把:

// Make sure a default time zone is set
if (ini_get('date.timezone') == '')
   date_default_timezone_set('America/Montreal');

改为:

// Make sure a default time zone is set
if (ini_get('date.timezone') == '')
   //date_default_timezone_set('America/Montreal');
   date_default_timezone_set('GMT');

结果,竟然还是问题依旧。

转载请注明:在路上 » 【未解决】Vanilla的bbs系统中,帖子的发布时间,显示不正常

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.149 seconds, using 22.15MB memory