GithubHelp home page GithubHelp logo

lki / chinese-calendar Goto Github PK

View Code? Open in Web Editor NEW
1.0K 26.0 182.0 196 KB

判断一天是不是法定节假日/法定工作日(查看节假日安排)

Home Page: https://pypi.org/project/chinesecalendar/

License: MIT License

Python 99.70% Makefile 0.30%
chinese-calendar calendar holidays workdays python chinese-holiday public-holidays

chinese-calendar's Introduction

**节假日

Package Travis License README

判断某年某月某一天是不是工作日/节假日。 支持 2004年 至 2024年,包括 2020年 的春节延长。

安装

pip install chinesecalendar

升级

pip install -U chinesecalendar

由于次年的节假日安排,取决于国务院发布的日程。 所以本项目一般会在国务院更新以后,发布新的版本。 按照以往的经验,一般是每年的 11月 前后发布新版本。

样例

import datetime

# 判断 2018年4月30号 是不是节假日
from chinese_calendar import is_holiday, is_workday
april_last = datetime.date(2018, 4, 30)
assert is_workday(april_last) is False
assert is_holiday(april_last) is True

# 或者在判断的同时,获取节日名
import chinese_calendar as calendar  # 也可以这样 import
on_holiday, holiday_name = calendar.get_holiday_detail(april_last)
assert on_holiday is True
assert holiday_name == calendar.Holiday.labour_day.value

# 还能判断法定节假日是不是调休
import chinese_calendar
assert chinese_calendar.is_in_lieu(datetime.date(2006, 2, 1)) is False
assert chinese_calendar.is_in_lieu(datetime.date(2006, 2, 2)) is True

其它语言

假如你没法使用Python, 你也可以转译现成的常量文件来获取最全的节假日安排表。

贡献代码

  1. Fork + Clone 项目到本地
  2. 修改节假日定义
  3. 执行脚本自动生成常量文件
  4. 提交PR

chinese-calendar's People

Contributors

calfzhou avatar dependabot[bot] avatar dragon-gcs avatar fhrl94 avatar ldsink avatar lijingcheng3359 avatar lki avatar luzihang123 avatar xiaomingtt avatar yqkcn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chinese-calendar's Issues

2005年holiday判断问题

您好,在对2005年-2013年日期进行判断时发现很多个周末会被判断为节假日
例如is_holiday(datetime.date(2005, 1, 16)) 返回True
chinese_calendar.get_holiday_detail(datetime.date(2005, 1, 16)) 返回(True, None)
这是什么情况呢

节假日

之后的节假日是需要手动添加吗,还是说会自动去爬取后边公布的节假日

以下这几个节假日有缺失

lose_holiday = {
'2019-06-08': 'Dragon Boat Festival',
'2019-06-09': 'Dragon Boat Festival',
'2019-09-14': 'Mid-autumn Festival',
'2019-09-15': 'Mid-autumn Festival',
'2019-09-21': 'Mid-autumn Festival',
'2019-04-06': 'Tomb-sweeping Day',
'2019-04-07': 'Tomb-sweeping Day',
}

判断是否是有休息的特殊节日

因为目前没有这个接口,所以只能查节日名 ,
但是我在数据里发现有个这个

    datetime.date(year=2015, month=9, day=3): Holiday.anti_fascist_70th_day.value,
    datetime.date(year=2015, month=9, day=4): Holiday.anti_fascist_70th_day.value,

我不记得15年有休过这个假日。。。
因为我是做数据分析的,要把特殊休息的节假日剔除掉,所以有用。


百度了一下,有说当时有调休。。。搞不清楚了

判断节假日的bug

判断 4月5日是否是节假日

march_first = today + datetime.timedelta(days=1)
is_workday(march_first)  

输出 FALSE
工作日和节假日判断错误。
原因是 march_first 是 datetime 类,不是 date 类。
但是 datetime 类才有 timedelta方法,进行日期的计算。
将 march_first 转换为 date 类。
示例代码如下

march_first = today + datetime.timedelta(days=1)
is_workday(march_first.date())

如果可以的话,将上面的的示例代码进行修改。。。。
或者将 datetime 类进行强制转换为 date 类。 @LKI

python 2.7.5 install chinesecalendar error

Downloading chinesecalendar-1.5.1.tar.gz (9.4 kB)
ERROR: Command errored out with exit status 1:
command: /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/tc/cls8jwsn6fd6hvmph42vxyp00000gn/T/pip-install-ZdYNb5/chinesecalendar/setup.py'"'"'; file='"'"'/private/var/folders/tc/cls8jwsn6fd6hvmph42vxyp00000gn/T/pip-install-ZdYNb5/chinesecalendar/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/tc/cls8jwsn6fd6hvmph42vxyp00000gn/T/pip-pip-egg-info-e9vti7
cwd: /private/var/folders/tc/cls8jwsn6fd6hvmph42vxyp00000gn/T/pip-install-ZdYNb5/chinesecalendar/
Complete output (5 lines):
Traceback (most recent call last):
File "", line 1, in
File "/private/var/folders/tc/cls8jwsn6fd6hvmph42vxyp00000gn/T/pip-install-ZdYNb5/chinesecalendar/setup.py", line 6, in
with open("README.md", "r", encoding="utf-8") as f:
TypeError: 'encoding' is an invalid keyword argument for this function
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

2015年端午节错误

datetime.date(year=2015, month=6, day=20): Holiday.dragon_boat_festival.value,
datetime.date(year=2015, month=6, day=22): Holiday.dragon_boat_festival.value,

五、端午节:6月20日放假,6月22日(星期一)补休。
http://www.gov.cn/zhengce/content/2014-12/16/content_9302.htm

应该是

datetime.date(year=2015, month=6, day=20): Holiday.dragon_boat_festival.value,
datetime.date(year=2015, month=6, day=21): Holiday.dragon_boat_festival.value,
datetime.date(year=2015, month=6, day=22): Holiday.dragon_boat_festival.value,

python2.7 导入报错

from chinese_calendar import is_holiday, is_workday
Traceback (most recent call last):
File "", line 1, in
File "/home/zhangyuzhou/Downloads/pycharm-community/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 20, in do_import
module = self._system_import(name, *args, **kwargs)
File "/home/zhangyuzhou/PycharmProjects/CmeomsSpider/env/local/lib/python2.7/site-packages/chinese_calendar/init.py", line 4, in
from .constants import Holiday
File "/home/zhangyuzhou/Downloads/pycharm-community/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 20, in do_import
module = self._system_import(name, *args, **kwargs)
File "/home/zhangyuzhou/PycharmProjects/CmeomsSpider/env/local/lib/python2.7/site-packages/chinese_calendar/constants.py", line 31, in
datetime.date(year=2006, month=1, day=1): Holiday.new_years_day.value,
AttributeError: 'tuple' object has no attribute 'value'

你忘了把 `requirements.txt` 包到 pypi 发布包里

Detail :
image

>>> pip install chinesecalendar -U
Collecting chinesecalendar
  Downloading https://files.pythonhosted.org/packages/85/c4/893db136ff403f2194ef664e19211712efdaa50de91762543a40e22ee827/chinesecalendar-1.2.2.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\xxxxx\AppData\Local\Temp\pip-install-fxjk3a1v\chinesecalendar\setup.py", line 4, in <module>
        with open('requirements.txt') as f:
    FileNotFoundError: [Errno 2] No such file or directory: 'requirements.txt'

希望支持 Python 3.7

python3 -m pip install chinese_calendar
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
ERROR: Could not find a version that satisfies the requirement chinese_calendar (from versions: none)
ERROR: No matching distribution found for chinese_calendar

既然支持 Python 3.6,3.7 下运行应该也没问题的

关于更新日期问题

如果要使用最新的日期,像现在马上要2022年了,是不是必须要更新版本才可以取到2022年的日期数据呀

建议统一一下节假日是否包含周末

目前看constants.py,节假日有的包含了连休的周末,有的没有包含,如2017年5月1日是劳动节,而2018年4月29、30和5月1日都是劳动节,是否可以统一一下?

calendar.get_holiday_detail error

我不知道底层怎么实现的,但是这个判断春节有明显的错误。
例如 2017-1-22 跟春节不搭边,却判断的是春节

Bug 2006-12-31

调用is_holiday(datetime.date(2005,12,31)) ,返回True,但那天是调休上班,类似的问题貌似还有

能否增加农历日子的判断

我每天有写计划和日志的习惯,希望能借助这个程序包实现农历信息的判断,方便我在写日志的时候,能自动提醒是哪个亲人的生日。

支持多种输入

  1. 支持其他时间表示方式:"2018-01-01" pandas.timestamp等
  2. 支持list, numpy.Array, pd.Series输入,提取时间特征

考虑使用更科学的接口

目前的方式是

import datetime

from chinese_calendar.utils import is_workday, is_holiday

march_first = datetime.date(2017, 5, 1)

print(is_workday(march_first))  # False

print(is_holiday(march_first))  # True

其实可以改成

import datetime

import chinese_calendar

march_first = datetime.date(2017, 5, 1)

print(chinese_calendar.is_workday(march_first))  # False

print(chinese_calendar.is_holiday(march_first))  # True

2019劳动节更新模块

最新的 12.2版本模块 劳动节2019好像没更新上,还是之前的 ,方便更新下吗

pip install chinesecalendar==1.2.1 错误

[root@localhost SMSBlessing_web]# pip3.6 install chinesecalendar==1.2.1
Collecting chinesecalendar==1.2.1
  Using cached https://files.pythonhosted.org/packages/8a/16/3581d813287b8d9db7deaf6e300dae2789d74acb73906c40996e35e5ff43/chinesecalendar-1.2.1.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-1xed56d2/chinesecalendar/setup.py", line 2, in <module>
        import pypandoc
    ModuleNotFoundError: No module named 'pypandoc'
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-1xed56d2/chinesecalendar/
[root@localhost SMSBlessing_web]# pip3.6 install chinesecalendar==1.2.1
Collecting chinesecalendar==1.2.1
  Using cached https://files.pythonhosted.org/packages/8a/16/3581d813287b8d9db7deaf6e300dae2789d74acb73906c40996e35e5ff43/chinesecalendar-1.2.1.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-7687iy1t/chinesecalendar/setup.py", line 2, in <module>
        import pypandoc
    ModuleNotFoundError: No module named 'pypandoc'
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-7687iy1t/chinesecalendar/

这个不是issue,这个是感谢信!

接近年底,定时任务突然报错,如不处理后果非常严重。查看程序报错原因为支持年份[2014, 2018],于是赶紧来到GitHub查看是否有更新,结果发现lz更新了啊啊啊啊!非常感谢您!

调休的定义是?

这个调休第一眼看过去有点奇怪

image

chinese_calendar.is_in_lieu(date(2018,9,30))
False
chinese_calendar.is_in_lieu(date(2018,10,1))
False
chinese_calendar.is_in_lieu(date(2018,10,2))
False
chinese_calendar.is_in_lieu(date(2018,10,3))
False
chinese_calendar.is_in_lieu(date(2018,10,4))
True
chinese_calendar.is_in_lieu(date(2018,10,5))
True
chinese_calendar.is_in_lieu(date(2018,10,6))
False
chinese_calendar.is_in_lieu(date(2018,10,7))
False

9.29, 9.30 休调班
10,4,10,5 班调休

一般是说 9.29, 9.30 调休到 10,4,10,5
这样区分下会更好吧

判断某一天是否为节假日当天

现在发现一个问题,比如国庆节七天假,十月一号返回节日名称没问题,但是之后的几天加也会返回国庆节,虽也说得过去,但是如果要实现在节日当天发送祝福语的话,就不能以此为准了,在十月一日之后的几天节日里每天提醒国庆节是不大合适的。烦请指点是否存在可区分实际节日当天和假日的解决方案
today = datetime.now()
on_holiday, holiday_name = calendar.get_holiday_detail(today)
return on_holiday, holiday_name

不调休判断假日与周末

金融行业中,就算是因为调休周末需要工作时,也是休息,不工作的。能否加个参数来忽略周末调休的情况?

比如 2020年2月1日:

chinese_calendar.is_holiday(datetime.date(2020,2,1))
False

实际这是一个周六,也是假日。

是否可以加入法定节假日和调休日区分呢?

按照国家加班工资规定:
在法定节假日,用人单位应当按照不低于日工资基数或者小时工资基数的300%来支付加班工资,而且不得以调休、补休替代。在休息日,用人单位应当先安排同等时间的补休;确实不能安排补休的,要按照不低于日工资基数或者小时工资基数的200%支付加班工资。

根据国家统一安排,2018年春节放假共七天,即2月15日至21日。其中,国家法定节假日有三天,即2月16日到18日,也就是农历正月初一、初二、初三;另外有四天是调休日,即2月15日、19日、20日、21日,这是由2月11日、17日、18日、24日这四个周末休息日调过来的。

也就是说,同样是节假日,法定假日和调休日的加班工资是不一样的。我这边做个项目,就要根据这个区分工资计算。

麻烦大神看下是否能支持?我不是专业搞python的。怕提交的代码不规范

清明节节假日错误

比如datetime.date(2014, 4, 7)应该是清明节放假日,但实际datetime.date(2014, 4, 7)返回False

节假日判断混乱。

用get_holiday_detail函数输出是否是节假日以及节假日名称时非常混乱。
比如 劳动节,只有2017-05-01号有name输出
而端午节,反而有2017-05-27到2017-05-30都算端午节,有name输出。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.