图灵教育的编程日历(其实是周历)每周使用一种程序设计语言以“YYYY-MM-DD”格式输出当天的日期。注意:这里的当天是指程序运行时的日期,而不是编程日历中的日期。10月份的第4周是 Haskell 语言:

但是,这个程序是有问题的:

根据给出的错误信息,删除 HackingDate.hs 的第2行就行了:

这个程序中用到的 getZonedTime, formatTime, defaultTimeLocale 等函数的信息如下:

$ ghci
GHCi, version 8.6.5: http://www.haskell.org/ghc/  :? for help
Prelude> :info Data.Time.getZonedTime
time-1.8.0.2:Data.Time.LocalTime.Internal.ZonedTime.getZonedTime ::
  IO time-1.8.0.2:Data.Time.LocalTime.Internal.ZonedTime.ZonedTime
      -- Defined in ‘time-1.8.0.2:Data.Time.LocalTime.Internal.ZonedTime’
Prelude> :info Data.Time.formatTime
Data.Time.Format.formatTime ::
  Data.Time.Format.FormatTime t =>
  time-1.8.0.2:Data.Time.Format.Locale.TimeLocale
  -> String -> t -> String
      -- Defined in ‘Data.Time.Format’
Prelude> :info Data.Time.defaultTimeLocale
time-1.8.0.2:Data.Time.Format.Locale.defaultTimeLocale ::
  time-1.8.0.2:Data.Time.Format.Locale.TimeLocale
      -- Defined in ‘time-1.8.0.2:Data.Time.Format.Locale’

其中,getZonedTime 返回当前的时间(带有时区信息):

Prelude> a <- Data.Time.getZonedTime
Prelude> a
2019-10-23 19:55:23.247136385 CST

这里的 CST 是 China Standard Time (UTC+8)。

Data.Time.defaultTimeLocale 的值:

Prelude> Data.Time.defaultTimeLocale
TimeLocale {wDays = [("Sunday","Sun"),("Monday","Mon"),("Tuesday","Tue"),("Wednesday","Wed"),("Thursday","Thu"),("Friday","Fri"),("Saturday","Sat")], months = [("January","Jan"),("February","Feb"),("March","Mar"),("April","Apr"),("May","May"),("June","Jun"),("July","Jul"),("August","Aug"),("September","Sep"),("October","Oct"),("November","Nov"),("December","Dec")], amPm = ("AM","PM"), dateTimeFmt = "%a %b %e %H:%M:%S %Z %Y", dateFmt = "%m/%d/%y", timeFmt = "%H:%M:%S", time12Fmt = "%I:%M:%S %p", knownTimeZones = [UT,GMT,EST,EDT,CST,CDT,MST,MDT,PST,PDT]}

这里的 CST 是 Central Standard Time (UTC-6)。

System.Locale.defaultTimeLocale 的值略有不同(没有时区相关的信息):

Prelude> System.Locale.defaultTimeLocale
TimeLocale {wDays = [("Sunday","Sun"),("Monday","Mon"),("Tuesday","Tue"),("Wednesday","Wed"),("Thursday","Thu"),("Friday","Fri"),("Saturday","Sat")], months = [("January","Jan"),("February","Feb"),("March","Mar"),("April","Apr"),("May","May"),("June","Jun"),("July","Jul"),("August","Aug"),("September","Sep"),("October","Oct"),("November","Nov"),("December","Dec")], intervals = [("year","years"),("month","months"),("day","days"),("hour","hours"),("min","mins"),("sec","secs"),("usec","usecs")], amPm = ("AM","PM"), dateTimeFmt = "%a %b %e %H:%M:%S %Z %Y", dateFmt = "%m/%d/%y", timeFmt = "%H:%M:%S", time12Fmt = "%I:%M:%S %p"}

时区信息