-
-
Notifications
You must be signed in to change notification settings - Fork 707
Add Singapore Exchange (SGX) holidays #3719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7ffbe41
Add Singapore Exchange (SGX) holidays
pareshjoshij c0743b5
Add Singapore Exchange (SGX) holidays
pareshjoshij 1ecbe67
Apply suggestions
pareshjoshij 329a4ec
update test
pareshjoshij 23d9c9e
Fix docstring formatting and remove redundant _move_holiday
pareshjoshij File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # holidays | ||
| # -------- | ||
| # A fast, efficient Python library for generating country, province and state | ||
| # specific sets of holidays on the fly. It aims to make determining whether a | ||
| # specific date is a holiday as fast and flexible as possible. | ||
| # | ||
| # Authors: Vacanza Team and individual contributors (see CONTRIBUTORS file) | ||
| # dr-prodigy <dr.prodigy.github@gmail.com> (c) 2017-2023 | ||
| # ryanss <ryanssdev@icloud.com> (c) 2014-2017 | ||
| # Website: https://github.com/vacanza/holidays | ||
| # License: MIT (see LICENSE file) | ||
|
|
||
| from gettext import gettext as tr | ||
|
|
||
| from holidays.constants import HALF_DAY, PUBLIC | ||
| from holidays.countries.singapore import Singapore | ||
|
|
||
|
|
||
| class SingaporeExchange(Singapore): | ||
| """Singapore Exchange (SGX) holidays. | ||
|
|
||
| References: | ||
| * <https://web.archive.org/web/20260725102849/https://www.sgx.com/stock-exchange/trading> | ||
| """ | ||
|
|
||
| country = None # type: ignore[assignment] | ||
| market = "XSES" | ||
| parent_entity = Singapore | ||
| supported_categories: tuple[str, ...] = (HALF_DAY, PUBLIC) # type: ignore[assignment] | ||
| start_year = 2000 | ||
| observed_label = "%s" | ||
|
|
||
| def _populate_common_holidays(self): | ||
| super()._populate_common_holidays() | ||
|
|
||
| for dt in tuple(self.keys()): | ||
| if self._is_weekend(dt): | ||
| self.pop(dt) | ||
|
|
||
| def _populate_half_day_holidays(self): | ||
| # %s (markets close at 12:00 p.m. SGT). | ||
| pause_label = tr("%s (markets close at 12:00 p.m. SGT)") | ||
|
|
||
| # Christmas Eve. | ||
| self._add_christmas_eve(self._format_holiday_name(pause_label, tr("Christmas Eve"))) | ||
|
|
||
| # New Year's Eve. | ||
| self._add_new_years_eve(self._format_holiday_name(pause_label, tr("New Year's Eve"))) | ||
|
|
||
| self._add_chinese_new_years_eve( | ||
| # Chinese New Year's Eve. | ||
| self._format_holiday_name(pause_label, tr("Chinese New Year's Eve")) | ||
| ) | ||
|
|
||
|
|
||
| class XSES(SingaporeExchange): | ||
| pass | ||
|
|
||
|
|
||
| class SGX(SingaporeExchange): | ||
| pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # holidays | ||
| # -------- | ||
| # A fast, efficient Python library for generating country, province and state | ||
| # specific sets of holidays on the fly. It aims to make determining whether a | ||
| # specific date is a holiday as fast and flexible as possible. | ||
| # | ||
| # Authors: Vacanza Team and individual contributors (see CONTRIBUTORS file) | ||
| # dr-prodigy <dr.prodigy.github@gmail.com> (c) 2017-2023 | ||
| # ryanss <ryanssdev@icloud.com> (c) 2014-2017 | ||
| # Website: https://github.com/vacanza/holidays | ||
| # License: MIT (see LICENSE file) | ||
| # | ||
| # Singapore Exchange (SGX) holidays. | ||
| # | ||
| msgid "" | ||
| msgstr "" | ||
| "Project-Id-Version: Holidays 0.102\n" | ||
| "Report-Msgid-Bugs-To: l10n@vacanza.dev\n" | ||
| "POT-Creation-Date: 2026-07-25 04:57+0000\n" | ||
| "PO-Revision-Date: 2026-07-25 14:54+0000\n" | ||
| "Last-Translator: Paresh Joshi <pareshjoshij@gmail.com>\n" | ||
| "Language-Team: Holidays Localization Team\n" | ||
| "Language: en_SG\n" | ||
| "MIME-Version: 1.0\n" | ||
| "Content-Type: text/plain; charset=UTF-8\n" | ||
| "Content-Transfer-Encoding: 8bit\n" | ||
| "Generated-By: Lingva 5.0.6\n" | ||
| "X-Source-Language: en_SG\n" | ||
|
|
||
| #. %s (markets close at 12:00 p.m. SGT). | ||
| #, c-format | ||
| msgid "%s (markets close at 12:00 p.m. SGT)" | ||
| msgstr "" | ||
|
|
||
| #. Christmas Eve. | ||
| msgid "Christmas Eve" | ||
| msgstr "" | ||
|
|
||
| #. New Year's Eve. | ||
| msgid "New Year's Eve" | ||
| msgstr "" | ||
|
|
||
| #. Chinese New Year's Eve. | ||
| msgid "Chinese New Year's Eve" | ||
| msgstr "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # holidays | ||
| # -------- | ||
| # A fast, efficient Python library for generating country, province and state | ||
| # specific sets of holidays on the fly. It aims to make determining whether a | ||
| # specific date is a holiday as fast and flexible as possible. | ||
| # | ||
| # Authors: Vacanza Team and individual contributors (see CONTRIBUTORS file) | ||
| # dr-prodigy <dr.prodigy.github@gmail.com> (c) 2017-2023 | ||
| # ryanss <ryanssdev@icloud.com> (c) 2014-2017 | ||
| # Website: https://github.com/vacanza/holidays | ||
| # License: MIT (see LICENSE file) | ||
| # | ||
| # Singapore Exchange (SGX) holidays en_US localization. | ||
| # | ||
| msgid "" | ||
| msgstr "" | ||
| "Project-Id-Version: Holidays 0.102\n" | ||
| "Report-Msgid-Bugs-To: l10n@vacanza.dev\n" | ||
| "POT-Creation-Date: 2026-07-25 04:57+0000\n" | ||
| "PO-Revision-Date: 2026-07-25 14:54+0000\n" | ||
| "Last-Translator: Paresh Joshi <pareshjoshij@gmail.com>\n" | ||
| "Language-Team: Holidays Localization Team\n" | ||
| "Language: en_US\n" | ||
| "MIME-Version: 1.0\n" | ||
| "Content-Type: text/plain; charset=UTF-8\n" | ||
| "Content-Transfer-Encoding: 8bit\n" | ||
| "Generated-By: Lingva 5.0.6\n" | ||
| "X-Source-Language: en_SG\n" | ||
|
|
||
| #. %s (markets close at 12:00 p.m. SGT). | ||
| #, c-format | ||
| msgid "%s (markets close at 12:00 p.m. SGT)" | ||
| msgstr "%s (markets close at 12:00 p.m. SGT)" | ||
|
|
||
| #. Christmas Eve. | ||
| msgid "Christmas Eve" | ||
| msgstr "Christmas Eve" | ||
|
|
||
| #. New Year's Eve. | ||
| msgid "New Year's Eve" | ||
| msgstr "New Year's Eve" | ||
|
|
||
| #. Chinese New Year's Eve. | ||
| msgid "Chinese New Year's Eve" | ||
| msgstr "Chinese New Year's Eve" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # holidays | ||
| # -------- | ||
| # A fast, efficient Python library for generating country, province and state | ||
| # specific sets of holidays on the fly. It aims to make determining whether a | ||
| # specific date is a holiday as fast and flexible as possible. | ||
| # | ||
| # Authors: Vacanza Team and individual contributors (see CONTRIBUTORS file) | ||
| # dr-prodigy <dr.prodigy.github@gmail.com> (c) 2017-2023 | ||
| # ryanss <ryanssdev@icloud.com> (c) 2014-2017 | ||
| # Website: https://github.com/vacanza/holidays | ||
| # License: MIT (see LICENSE file) | ||
| # | ||
| # Singapore Exchange (SGX) holidays th localization. | ||
| # | ||
| msgid "" | ||
| msgstr "" | ||
| "Project-Id-Version: Holidays 0.102\n" | ||
| "Report-Msgid-Bugs-To: l10n@vacanza.dev\n" | ||
| "POT-Creation-Date: 2026-07-25 04:57+0000\n" | ||
| "PO-Revision-Date: 2026-07-25 14:54+0000\n" | ||
| "Last-Translator: Paresh Joshi <pareshjoshij@gmail.com>\n" | ||
| "Language-Team: Holidays Localization Team\n" | ||
| "Language: th\n" | ||
| "MIME-Version: 1.0\n" | ||
| "Content-Type: text/plain; charset=UTF-8\n" | ||
| "Content-Transfer-Encoding: 8bit\n" | ||
| "Generated-By: Lingva 5.0.6\n" | ||
| "X-Source-Language: en_SG\n" | ||
|
|
||
| #. %s (markets close at 12:00 p.m. SGT). | ||
| #, c-format | ||
| msgid "%s (markets close at 12:00 p.m. SGT)" | ||
| msgstr "%s (ตลาดปิดเวลา 12:00 น. SGT)" | ||
|
|
||
| #. Christmas Eve. | ||
| msgid "Christmas Eve" | ||
| msgstr "วันคริสต์มาสอีฟ" | ||
|
|
||
| #. New Year's Eve. | ||
| msgid "New Year's Eve" | ||
| msgstr "วันสิ้นปี" | ||
|
|
||
| #. Chinese New Year's Eve. | ||
| msgid "Chinese New Year's Eve" | ||
| msgstr "วันก่อนวันตรุษจีน" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| # holidays | ||
| # -------- | ||
| # A fast, efficient Python library for generating country, province and state | ||
| # specific sets of holidays on the fly. It aims to make determining whether a | ||
| # specific date is a holiday as fast and flexible as possible. | ||
| # | ||
| # Authors: Vacanza Team and individual contributors (see CONTRIBUTORS file) | ||
| # dr-prodigy <dr.prodigy.github@gmail.com> (c) 2017-2023 | ||
| # ryanss <ryanssdev@icloud.com> (c) 2014-2017 | ||
| # Website: https://github.com/vacanza/holidays | ||
| # License: MIT (see LICENSE file) | ||
|
|
||
| from unittest import TestCase | ||
|
|
||
| from holidays.financial.singapore_exchange import SingaporeExchange | ||
| from tests.common import CommonFinancialTests | ||
|
|
||
|
|
||
| class TestSingaporeExchange(CommonFinancialTests, TestCase): | ||
| @classmethod | ||
| def setUpClass(cls): | ||
| cls.full_range = range(2000, 2027) | ||
| super().setUpClass(SingaporeExchange) | ||
|
|
||
| def test_code(self): | ||
| self.assertTrue(hasattr(self.holidays, "market")) | ||
| self.assertIsNone(getattr(self.holidays, "country", None)) | ||
|
|
||
| def test_christmas_eve(self): | ||
| name = "Christmas Eve (markets close at 12:00 p.m. SGT)" | ||
| years_absent = {2000, 2005, 2006, 2011, 2016, 2017, 2022, 2023} | ||
| self.assertNoHolidayName(name) | ||
| self.assertNoHalfDayHolidayName(name, (f"{year}-12-24" for year in years_absent)) | ||
| self.assertHalfDayNonObservedHolidayName( | ||
| name, (f"{year}-12-24" for year in self.full_range if year not in years_absent) | ||
| ) | ||
|
|
||
| def test_new_years_eve(self): | ||
| name = "New Year's Eve (markets close at 12:00 p.m. SGT)" | ||
| years_absent = {2000, 2005, 2006, 2011, 2016, 2017, 2022, 2023} | ||
| self.assertNoHolidayName(name) | ||
| self.assertNoHalfDayHolidayName(name, (f"{year}-12-31" for year in years_absent)) | ||
| self.assertHalfDayNonObservedHolidayName( | ||
| name, (f"{year}-12-31" for year in self.full_range if year not in years_absent) | ||
| ) | ||
|
|
||
| def test_chinese_new_years_eve(self): | ||
| name = "Chinese New Year's Eve (markets close at 12:00 p.m. SGT)" | ||
| self.assertNoHolidayName(name) | ||
| self.assertHalfDayHolidayName( | ||
| name, | ||
| "2020-01-24", | ||
| "2021-02-11", | ||
| "2022-01-31", | ||
| "2024-02-09", | ||
| "2025-01-28", | ||
| "2026-02-16", | ||
| ) | ||
| self.assertNoHalfDayHolidayName( | ||
| name, | ||
| "2023-01-21", | ||
| ) | ||
|
|
||
| def test_2025(self): | ||
| self.assertHolidaysInYear( | ||
| 2025, | ||
| ("2025-01-01", "New Year's Day"), | ||
| ("2025-01-29", "Chinese New Year"), | ||
| ("2025-01-30", "Chinese New Year"), | ||
| ("2025-03-31", "Hari Raya Puasa"), | ||
| ("2025-04-18", "Good Friday"), | ||
| ("2025-05-01", "Labour Day"), | ||
| ("2025-05-12", "Vesak Day"), | ||
| ("2025-10-20", "Deepavali"), | ||
| ("2025-12-25", "Christmas Day"), | ||
| ) | ||
|
|
||
| def test_half_day_2025(self): | ||
| self.assertHalfDayHolidaysInYear( | ||
| 2025, | ||
| ("2025-01-28", "Chinese New Year's Eve (markets close at 12:00 p.m. SGT)"), | ||
| ("2025-12-24", "Christmas Eve (markets close at 12:00 p.m. SGT)"), | ||
| ("2025-12-31", "New Year's Eve (markets close at 12:00 p.m. SGT)"), | ||
| ) | ||
|
|
||
| def test_l10n_default(self): | ||
| self.assertLocalizedHolidays( | ||
| ("2024-01-01", "New Year's Day"), | ||
| ("2024-02-09", "Chinese New Year's Eve (markets close at 12:00 p.m. SGT)"), | ||
| ("2024-02-12", "Chinese New Year"), | ||
| ("2024-03-29", "Good Friday"), | ||
| ("2024-04-10", "Hari Raya Puasa"), | ||
| ("2024-05-01", "Labour Day"), | ||
| ("2024-05-22", "Vesak Day"), | ||
| ("2024-06-17", "Hari Raya Haji"), | ||
| ("2024-08-09", "National Day"), | ||
| ("2024-10-31", "Deepavali"), | ||
| ("2024-12-24", "Christmas Eve (markets close at 12:00 p.m. SGT)"), | ||
| ("2024-12-25", "Christmas Day"), | ||
| ("2024-12-31", "New Year's Eve (markets close at 12:00 p.m. SGT)"), | ||
| ) | ||
|
|
||
| def test_l10n_en_us(self): | ||
| self.assertLocalizedHolidays( | ||
| "en_US", | ||
| ("2024-01-01", "New Year's Day"), | ||
| ("2024-02-09", "Chinese New Year's Eve (markets close at 12:00 p.m. SGT)"), | ||
| ("2024-02-12", "Chinese New Year"), | ||
| ("2024-03-29", "Good Friday"), | ||
| ("2024-04-10", "Eid al-Fitr"), | ||
| ("2024-05-01", "Labor Day"), | ||
| ("2024-05-22", "Vesak Day"), | ||
| ("2024-06-17", "Eid al-Adha"), | ||
| ("2024-08-09", "National Day"), | ||
| ("2024-10-31", "Deepavali"), | ||
| ("2024-12-24", "Christmas Eve (markets close at 12:00 p.m. SGT)"), | ||
| ("2024-12-25", "Christmas Day"), | ||
| ("2024-12-31", "New Year's Eve (markets close at 12:00 p.m. SGT)"), | ||
| ) | ||
|
|
||
| def test_l10n_th(self): | ||
| self.assertLocalizedHolidays( | ||
| "th", | ||
| ("2024-01-01", "วันขึ้นปีใหม่"), | ||
| ("2024-02-09", "วันก่อนวันตรุษจีน (ตลาดปิดเวลา 12:00 น. SGT)"), | ||
| ("2024-02-12", "วันตรุษจีน"), | ||
| ("2024-03-29", "วันศุกร์ประเสริฐ"), | ||
| ("2024-04-10", "วันอีฎิ้ลฟิตริ"), | ||
| ("2024-05-01", "วันแรงงาน"), | ||
| ("2024-05-22", "วันวิสาขบูชา"), | ||
| ("2024-06-17", "วันอีดิ้ลอัฎฮา"), | ||
| ("2024-08-09", "วันชาติสิงคโปร์"), | ||
| ("2024-10-31", "วันดีปาวลี"), | ||
| ("2024-12-24", "วันคริสต์มาสอีฟ (ตลาดปิดเวลา 12:00 น. SGT)"), | ||
| ("2024-12-25", "วันคริสต์มาส"), | ||
| ("2024-12-31", "วันสิ้นปี (ตลาดปิดเวลา 12:00 น. SGT)"), | ||
| ) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.