|
1 | 1 | # -*- coding: utf-8 -*-
|
2 | 2 | # cython: profile=False
|
3 | 3 | import warnings
|
| 4 | +import locale |
| 5 | + |
| 6 | +from pandas.util.testing import set_locale |
4 | 7 |
|
5 | 8 | from cpython cimport (PyObject_RichCompareBool, PyObject_RichCompare,
|
6 | 9 | Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE)
|
@@ -34,6 +37,7 @@ from np_datetime cimport (reverse_ops, cmp_scalar, check_dts_bounds,
|
34 | 37 | from timedeltas import Timedelta
|
35 | 38 | from timedeltas cimport delta_to_nanoseconds
|
36 | 39 | from timezones cimport get_timezone, is_utc, maybe_get_tz, treat_tz_as_pytz
|
| 40 | +from strptime import LocaleTime |
37 | 41 |
|
38 | 42 | # ----------------------------------------------------------------------
|
39 | 43 | # Constants
|
@@ -685,8 +689,59 @@ class Timestamp(_Timestamp):
|
685 | 689 | def dayofweek(self):
|
686 | 690 | return self.weekday()
|
687 | 691 |
|
| 692 | + def day_name(self, time_locale=None): |
| 693 | + """ |
| 694 | + Return the day name of the Timestamp with specified locale. |
| 695 | +
|
| 696 | + Parameters |
| 697 | + ---------- |
| 698 | + time_locale : string, default None (English locale) |
| 699 | + locale determining the language in which to return the day name |
| 700 | +
|
| 701 | + Returns |
| 702 | + ------- |
| 703 | + day_name : string |
| 704 | + """ |
| 705 | + if time_locale is None: |
| 706 | + days = {0: 'monday', 1: 'tuesday', 2: 'wednesday', |
| 707 | + 3: 'thursday', 4: 'friday', 5: 'saturday', |
| 708 | + 6: 'sunday'} |
| 709 | + else: |
| 710 | + with set_locale(time_locale, locale.LC_TIME): |
| 711 | + locale_time = LocaleTime() |
| 712 | + days = dict(enumerate(locale_time.f_weekday)) |
| 713 | + return days[self.weekday()].capitalize() |
| 714 | + |
| 715 | + def month_name(self, time_locale=None): |
| 716 | + """ |
| 717 | + Return the month name of the Timestamp with specified locale. |
| 718 | +
|
| 719 | + Parameters |
| 720 | + ---------- |
| 721 | + time_locale : string, default None (English locale) |
| 722 | + locale determining the language in which to return the month name |
| 723 | +
|
| 724 | + Returns |
| 725 | + ------- |
| 726 | + month_name : string |
| 727 | + """ |
| 728 | + if time_locale is None: |
| 729 | + months = {1: 'january', 2: 'february', 3: 'march', |
| 730 | + 4: 'april', 5: 'may', 6: 'june', 7: 'july', |
| 731 | + 8: 'august', 9: 'september', 10: 'october', |
| 732 | + 11: 'november', 12: 'december'} |
| 733 | + else: |
| 734 | + with set_locale(time_locale, locale.LC_TIME): |
| 735 | + locale_time = LocaleTime() |
| 736 | + months = dict(enumerate(locale_time.f_month)) |
| 737 | + return months[self.month].capitalize() |
| 738 | + |
688 | 739 | @property
|
689 | 740 | def weekday_name(self):
|
| 741 | + """ |
| 742 | + .. depreciated:: 0.23.0 |
| 743 | + Use ``Timestamp.day_name()`` instead |
| 744 | + """ |
690 | 745 | cdef dict wdays = {0: 'Monday', 1: 'Tuesday', 2: 'Wednesday',
|
691 | 746 | 3: 'Thursday', 4: 'Friday', 5: 'Saturday',
|
692 | 747 | 6: 'Sunday'}
|
|
0 commit comments