diff --git a/lib/hexo/validate_config.ts b/lib/hexo/validate_config.ts index ffb4a5a3..818e8558 100644 --- a/lib/hexo/validate_config.ts +++ b/lib/hexo/validate_config.ts @@ -1,4 +1,5 @@ import assert from 'assert'; +import moment from 'moment-timezone'; import type Hexo from './index'; export = (ctx: Hexo): void => { @@ -24,5 +25,23 @@ export = (ctx: Hexo): void => { if (config.root.trim().length <= 0) { throw new TypeError('Invalid config detected: "root" should not be empty!'); } -}; + if (!config.timezone) { + log.warn('No timezone setting detected! Using LocalTimeZone as the default timezone.'); + log.warn('This behavior will be changed to UTC in the next major version. Please set timezone explicitly (e.g. LocalTimeZone or America/New_York) in _config.yml to avoid this warning.'); + } else { + const configTimezone = moment.tz.zone(config.timezone); + if (!configTimezone) { + log.warn( + `Invalid timezone setting detected! "${config.timezone}" is not a valid timezone.` + ); + } else { + const machineTimezone = moment.tz.guess(); + if (configTimezone.name !== machineTimezone) { + log.warn( + `The timezone "${config.timezone}" setting is different from your machine timezone "${machineTimezone}". Make sure this is intended.` + ); + } + } + } +};