def from_jd(jd):
jd = trunc(jd) + <NUM_LIT:0.5><EOL>g = gregorian.from_jd(jd)<EOL>gy = g[<NUM_LIT:0>]<EOL>bstarty = EPOCH_GREGORIAN_YEAR<EOL>if jd <= gregorian.to_jd(gy, <NUM_LIT:3>, <NUM_LIT:20>):<EOL><INDENT>x = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>x = <NUM_LIT:0><EOL><DEDENT>bys = gy - (bstarty + (((gregorian.to_jd(gy, <NUM_LIT:1>, <NUM_LIT:1>) <= jd) and x)))<EOL>year = bys + <NUM_LIT:1><EOL>days = jd - to_jd(year, <NUM_LIT:1>, <NUM_LIT:1>)<EOL>bld = to_jd(year, <NUM_LIT:20>, <NUM_LIT:1>)<EOL>if jd >= bld:<EOL><INDENT>month = <NUM_LIT:20><EOL><DEDENT>else:<EOL><INDENT>month = trunc(days / <NUM_LIT>) + <NUM_LIT:1><EOL><DEDENT>day = int((jd + <NUM_LIT:1>) - to_jd(year, month, <NUM_LIT:1>))<EOL>return year, month, day<EOL>
Calculate Bahai date from Julian day