5
$\begingroup$

I tried to make a custom holiday calendar for the Korean Stock Exchange. And I found that the built-in "ChineseLunar" calendar system gives me an awkward result.

The code is

DateList /@ DayRange[{2012, 1, 1}, {2014, 3, 1}, "Holiday", HolidayCalendar -> {"ChineseLunar" -> {{True &, (#1 == 1) &, (#1 == 1) &}}}]

And the result is

{{2012, 1, 23, 0, 0, 0.}, {2014, 1, 31, 0, 0, 0.}}

Where is the date for 2013?

And what surprised me is

DateList /@ DayRange[{2012, 1, 1}, {2014, 3, 1}, "Holiday", HolidayCalendar -> {"ChineseLunar" -> {{True &, (#1 == 1) &, (#1 == 1||#1 == 2) &}}}]

gives me

{{2012, 1, 23, 0, 0, 0.}, {2012, 1, 24, 0, 0, 0.}, {2013, 2, 11, 0, 0, 0.}, {2014, 1, 31, 0, 0, 0.}}

I supposed it should return two dates for each year.

I appreciate any help.

Thanks in advance.

$\endgroup$
  • $\begingroup$ looks like a bug to me. $\endgroup$ – Nasser Nov 30 '14 at 7:30
  • $\begingroup$ @Nasser Unexpected answer :) If so, any alternatives? $\endgroup$ – Y. Kwon Nov 30 '14 at 8:07
  • 2
    $\begingroup$ Well, it is clear it is a bug. It missed a whole year. But I never used this command, just looked it up now. You can wait for others to suggest something. Might be useful to send email to support@wolfram.com with small example showing the problem. $\endgroup$ – Nasser Nov 30 '14 at 8:24
1
$\begingroup$

This is not a perfect but working solution. I installed a python package "lunisolar"

ConvertCalendar[date_List, "Gregorian" -> "ChineseLunar"] := 
  Flatten@Import[StringJoin[
    "!/usr/local/bin/python -c 'from lunisolar import ChineseDate;c = \
ChineseDate.from_gregorian(", DateString[date, 
 {"Year", ",", "Month", ",","Day"}], ");print \"%s,%s,%s,%s\" % (c.year, c.month, c.day, \
c.is_leap_month)'"], "CSV"]

ConvertCalendar[date_List, "ChineseLunar" -> "Gregorian"] :=
Flatten@Import[
  StringJoin[
    "!/usr/local/bin/python -c 'from lunisolar import ChineseDate;g = \
ChineseDate.from_chinese(",
    DateString[
      Take[date, 3], {"Year", ",", "Month", ",", "Day", ",",
      Last[date]}],
    ").gregorian_date;print \"%s,%s,%s\" % (g.year, g.month, g.day)'"], "CSV"]

Example:

In[1] = ConvertCalendar[{2014, 1, 1}, "Gregorian" -> "ChineseLunar"]
Out[1]= {2013, 12, 1, "False"}
In[2] = ConvertCalendar[{2014, 1, 1, "False"}, "ChineseLunar" -> "Gregorian"]
Out[2]= {2014, 1, 31}

"False" means it's not a leap month.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.