2 * Copyright (C) 2003-2004, International Business Machines Corporation
3 * and others. All Rights Reserved.
4 ******************************************************************************
8 * Modification History:
10 * Date Name Description
11 * 12/03/2003 srl ported from java HebrewCalendar
12 *****************************************************************************
17 #if !UCONFIG_NO_FORMATTING
21 #include "gregoimp.h" // Math
22 #include "astro.h" // CalendarAstronomer
26 // Hebrew Calendar implementation
29 * The absolute date, in milliseconds since 1/1/1970 AD, Gregorian,
30 * of the start of the Hebrew calendar. In order to keep this calendar's
31 * time of day in sync with that of the Gregorian calendar, we use
32 * midnight, rather than sunset the day before.
34 static const double EPOCH_MILLIS
= -180799862400000.; // 1/1/1 HY
36 static const int32_t LIMITS
[UCAL_FIELD_COUNT
][4] = {
37 // Minimum Greatest Least Maximum
39 { 0, 0, 0, 0 }, // ERA
40 { 1, 1, 5000000, 5000000 }, // YEAR
41 { 0, 0, 12, 12 }, // MONTH
42 { 1, 1, 51, 56 }, // WEEK_OF_YEAR
43 { 0, 0, 5, 6 }, // WEEK_OF_MONTH
44 { 1, 1, 29, 30 }, // DAY_OF_MONTH
45 { 1, 1, 353, 385 }, // DAY_OF_YEAR
46 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DAY_OF_WEEK
47 { -1, -1, 4, 6 }, // DAY_OF_WEEK_IN_MONTH
48 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1/* */}, // AM_PM
49 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // HOUR
50 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // HOUR_OF_DAY
51 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MINUTE
52 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // SECOND
53 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MILLISECOND
54 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // ZONE_OFFSET
55 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DST_OFFSET
56 { -5000001, -5000001, 5000001, 5000001 }, // YEAR_WOY
57 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // DOW_LOCAL
58 { -5000000, -5000000, 5000000, 5000000 }, // EXTENDED_YEAR
59 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // JULIAN_DAY
60 {/*N/A*/-1,/*N/A*/-1,/*N/A*/-1,/*N/A*/-1}, // MILLISECONDS_IN_DAY
64 * The lengths of the Hebrew months. This is complicated, because there
65 * are three different types of years, or six if you count leap years.
66 * Due to the rules for postponing the start of the year to avoid having
67 * certain holidays fall on the sabbath, the year can end up being three
68 * different lengths, called "deficient", "normal", and "complete".
70 static const int32_t MONTH_LENGTH
[][3] = {
71 // Deficient Normal Complete
72 { 30, 30, 30 }, //Tishri
73 { 29, 29, 30 }, //Heshvan
74 { 29, 30, 30 }, //Kislev
75 { 29, 29, 29 }, //Tevet
76 { 30, 30, 30 }, //Shevat
77 { 30, 30, 30 }, //Adar I (leap years only)
78 { 29, 29, 29 }, //Adar
79 { 30, 30, 30 }, //Nisan
80 { 29, 29, 29 }, //Iyar
81 { 30, 30, 30 }, //Sivan
82 { 29, 29, 29 }, //Tammuz
84 { 29, 29, 29 }, //Elul
88 * The cumulative # of days to the end of each month in a non-leap year
89 * Although this can be calculated from the MONTH_LENGTH table,
90 * keeping it around separately makes some calculations a lot faster
93 static const int32_t MONTH_START
[][3] = {
94 // Deficient Normal Complete
95 { 0, 0, 0 }, // (placeholder)
96 { 30, 30, 30 }, // Tishri
97 { 59, 59, 60 }, // Heshvan
98 { 88, 89, 90 }, // Kislev
99 { 117, 118, 119 }, // Tevet
100 { 147, 148, 149 }, // Shevat
101 { 147, 148, 149 }, // (Adar I placeholder)
102 { 176, 177, 178 }, // Adar
103 { 206, 207, 208 }, // Nisan
104 { 235, 236, 237 }, // Iyar
105 { 265, 266, 267 }, // Sivan
106 { 294, 295, 296 }, // Tammuz
107 { 324, 325, 326 }, // Av
108 { 353, 354, 355 }, // Elul
112 * The cumulative # of days to the end of each month in a leap year
114 static const int32_t LEAP_MONTH_START
[][3] = {
115 // Deficient Normal Complete
116 { 0, 0, 0 }, // (placeholder)
117 { 30, 30, 30 }, // Tishri
118 { 59, 59, 60 }, // Heshvan
119 { 88, 89, 90 }, // Kislev
120 { 117, 118, 119 }, // Tevet
121 { 147, 148, 149 }, // Shevat
122 { 177, 178, 179 }, // Adar I
123 { 206, 207, 208 }, // Adar II
124 { 236, 237, 238 }, // Nisan
125 { 265, 266, 267 }, // Iyar
126 { 295, 296, 297 }, // Sivan
127 { 324, 325, 326 }, // Tammuz
128 { 354, 355, 356 }, // Av
129 { 383, 384, 385 }, // Elul
132 static CalendarCache
*gCache
= NULL
;
135 static UBool
calendar_hebrew_cleanup(void) {
143 //-------------------------------------------------------------------------
145 //-------------------------------------------------------------------------
148 * Constructs a default <code>HebrewCalendar</code> using the current time
149 * in the default time zone with the default locale.
152 HebrewCalendar::HebrewCalendar(const Locale
& aLocale
, UErrorCode
& success
)
153 : Calendar(TimeZone::createDefault(), aLocale
, success
)
156 setTimeInMillis(getNow(), success
); // Call this again now that the vtable is set up properly.
160 HebrewCalendar::~HebrewCalendar() {
163 const char *HebrewCalendar::getType() const {
167 Calendar
* HebrewCalendar::clone() const {
168 return new HebrewCalendar(*this);
171 HebrewCalendar::HebrewCalendar(const HebrewCalendar
& other
) : Calendar(other
) {
175 //-------------------------------------------------------------------------
176 // Rolling and adding functions overridden from Calendar
178 // These methods call through to the default implementation in IBMCalendar
179 // for most of the fields and only handle the unusual ones themselves.
180 //-------------------------------------------------------------------------
183 * Add a signed amount to a specified field, using this calendar's rules.
184 * For example, to add three days to the current date, you can call
185 * <code>add(Calendar.DATE, 3)</code>.
187 * When adding to certain fields, the values of other fields may conflict and
188 * need to be changed. For example, when adding one to the {@link #MONTH MONTH} field
189 * for the date "30 Av 5758", the {@link #DAY_OF_MONTH DAY_OF_MONTH} field
190 * must be adjusted so that the result is "29 Elul 5758" rather than the invalid
193 * This method is able to add to
194 * all fields except for {@link #ERA ERA}, {@link #DST_OFFSET DST_OFFSET},
195 * and {@link #ZONE_OFFSET ZONE_OFFSET}.
197 * <b>Note:</b> You should always use {@link #roll roll} and add rather
198 * than attempting to perform arithmetic operations directly on the fields
199 * of a <tt>HebrewCalendar</tt>. Since the {@link #MONTH MONTH} field behaves
200 * discontinuously in non-leap years, simple arithmetic can give invalid results.
202 * @param field the time field.
203 * @param amount the amount to add to the field.
205 * @exception IllegalArgumentException if the field is invalid or refers
206 * to a field that cannot be handled by this method.
209 void HebrewCalendar::add(UCalendarDateFields field
, int32_t amount
, UErrorCode
& status
)
211 if(U_FAILURE(status
)) {
217 // We can't just do a set(MONTH, get(MONTH) + amount). The
218 // reason is ADAR_1. Suppose amount is +2 and we land in
219 // ADAR_1 -- then we have to bump to ADAR_2 aka ADAR. But
220 // if amount is -2 and we land in ADAR_1, then we have to
221 // bump the other way -- down to SHEVAT. - Alan 11/00
222 int32_t month
= get(UCAL_MONTH
, status
);
223 int32_t year
= get(UCAL_YEAR
, status
);
226 acrossAdar1
= (month
< ADAR_1
); // started before ADAR_1?
229 if (acrossAdar1
&& month
>=ADAR_1
&& !isLeapYear(year
)) {
240 acrossAdar1
= (month
> ADAR_1
); // started after ADAR_1?
243 if (acrossAdar1
&& month
<=ADAR_1
&& !isLeapYear(year
)) {
254 set(UCAL_MONTH
, month
);
255 set(UCAL_YEAR
, year
);
256 pinField(UCAL_DAY_OF_MONTH
, status
);
261 Calendar::add(field
, amount
, status
);
267 * Rolls (up/down) a specified amount time on the given field. For
268 * example, to roll the current date up by three days, you can call
269 * <code>roll(Calendar.DATE, 3)</code>. If the
270 * field is rolled past its maximum allowable value, it will "wrap" back
271 * to its minimum and continue rolling.
272 * For example, calling <code>roll(Calendar.DATE, 10)</code>
273 * on a Hebrew calendar set to "25 Av 5758" will result in the date "5 Av 5758".
275 * When rolling certain fields, the values of other fields may conflict and
276 * need to be changed. For example, when rolling the {@link #MONTH MONTH} field
277 * upward by one for the date "30 Av 5758", the {@link #DAY_OF_MONTH DAY_OF_MONTH} field
278 * must be adjusted so that the result is "29 Elul 5758" rather than the invalid
281 * This method is able to roll
282 * all fields except for {@link #ERA ERA}, {@link #DST_OFFSET DST_OFFSET},
283 * and {@link #ZONE_OFFSET ZONE_OFFSET}. Subclasses may, of course, add support for
284 * additional fields in their overrides of <code>roll</code>.
286 * <b>Note:</b> You should always use roll and {@link #add add} rather
287 * than attempting to perform arithmetic operations directly on the fields
288 * of a <tt>HebrewCalendar</tt>. Since the {@link #MONTH MONTH} field behaves
289 * discontinuously in non-leap years, simple arithmetic can give invalid results.
291 * @param field the time field.
292 * @param amount the amount by which the field should be rolled.
294 * @exception IllegalArgumentException if the field is invalid or refers
295 * to a field that cannot be handled by this method.
298 void HebrewCalendar::roll(UCalendarDateFields field
, int32_t amount
, UErrorCode
& status
)
300 if(U_FAILURE(status
)) {
306 int32_t month
= get(UCAL_MONTH
, status
);
307 int32_t year
= get(UCAL_YEAR
, status
);
309 UBool leapYear
= isLeapYear(year
);
310 int32_t yearLength
= monthsInYear(year
);
311 int32_t newMonth
= month
+ (amount
% yearLength
);
313 // If it's not a leap year and we're rolling past the missing month
314 // of ADAR_1, we need to roll an extra month to make up for it.
317 if (amount
> 0 && month
< ADAR_1
&& newMonth
>= ADAR_1
) {
319 } else if (amount
< 0 && month
> ADAR_1
&& newMonth
<= ADAR_1
) {
323 set(UCAL_MONTH
, (newMonth
+ 13) % 13);
324 pinField(UCAL_DAY_OF_MONTH
, status
);
328 Calendar::roll(field
, amount
, status
);
332 void HebrewCalendar::roll(EDateFields field
, int32_t amount
, UErrorCode
& status
) {
333 roll((UCalendarDateFields
)field
, amount
, status
);
336 //-------------------------------------------------------------------------
338 //-------------------------------------------------------------------------
340 // Hebrew date calculations are performed in terms of days, hours, and
341 // "parts" (or halakim), which are 1/1080 of an hour, or 3 1/3 seconds.
342 static const int32_t HOUR_PARTS
= 1080;
343 static const int32_t DAY_PARTS
= 24*HOUR_PARTS
;
345 // An approximate value for the length of a lunar month.
346 // It is used to calculate the approximate year and month of a given
348 static const int32_t MONTH_DAYS
= 29;
349 static const int32_t MONTH_FRACT
= 12*HOUR_PARTS
+ 793;
350 static const int32_t MONTH_PARTS
= MONTH_DAYS
*DAY_PARTS
+ MONTH_FRACT
;
352 // The time of the new moon (in parts) on 1 Tishri, year 1 (the epoch)
353 // counting from noon on the day before. BAHARAD is an abbreviation of
354 // Bet (Monday), Hey (5 hours from sunset), Resh-Daled (204).
355 static const int32_t BAHARAD
= 11*HOUR_PARTS
+ 204;
358 * Finds the day # of the first day in the given Hebrew year.
359 * To do this, we want to calculate the time of the Tishri 1 new moon
362 * The algorithm here is similar to ones described in a number of
363 * references, including:
365 * <li>"Calendrical Calculations", by Nachum Dershowitz & Edward Reingold,
366 * Cambridge University Press, 1997, pages 85-91.
368 * <li>Hebrew Calendar Science and Myths,
369 * <a href="http://www.geocities.com/Athens/1584/">
370 * http://www.geocities.com/Athens/1584/</a>
372 * <li>The Calendar FAQ,
373 * <a href="http://www.faqs.org/faqs/calendars/faq/">
374 * http://www.faqs.org/faqs/calendars/faq/</a>
377 int32_t HebrewCalendar::startOfYear(int32_t year
, UErrorCode
&status
)
379 ucln_i18n_registerCleanup(UCLN_I18N_HEBREW_CALENDAR
, calendar_hebrew_cleanup
);
380 int32_t day
= CalendarCache::get(&gCache
, year
, status
);
383 int32_t months
= (235 * year
- 234) / 19; // # of months before year
385 int32_t frac
= months
* MONTH_FRACT
+ BAHARAD
; // Fractional part of day #
386 day
= months
* 29 + (frac
/ DAY_PARTS
); // Whole # part of calculation
387 frac
= frac
% DAY_PARTS
; // Time of day
389 int32_t wd
= (day
% 7); // Day of week (0 == Monday)
391 if (wd
== 2 || wd
== 4 || wd
== 6) {
392 // If the 1st is on Sun, Wed, or Fri, postpone to the next day
396 if (wd
== 1 && frac
> 15*HOUR_PARTS
+204 && !isLeapYear(year
) ) {
397 // If the new moon falls after 3:11:20am (15h204p from the previous noon)
398 // on a Tuesday and it is not a leap year, postpone by 2 days.
399 // This prevents 356-day years.
402 else if (wd
== 0 && frac
> 21*HOUR_PARTS
+589 && isLeapYear(year
-1) ) {
403 // If the new moon falls after 9:32:43 1/3am (21h589p from yesterday noon)
404 // on a Monday and *last* year was a leap year, postpone by 1 day.
405 // Prevents 382-day years.
408 CalendarCache::put(&gCache
, year
, day
, status
);
414 * Find the day of the week for a given day
416 * @param day The # of days since the start of the Hebrew calendar,
417 * 1-based (i.e. 1/1/1 AM is day 1).
419 int32_t HebrewCalendar::absoluteDayToDayOfWeek(int32_t day
)
421 // We know that 1/1/1 AM is a Monday, which makes the math easy...
422 return (day
% 7) + 1;
426 * Returns the the type of a given year.
427 * 0 "Deficient" year with 353 or 383 days
428 * 1 "Normal" year with 354 or 384 days
429 * 2 "Complete" year with 355 or 385 days
431 int32_t HebrewCalendar::yearType(int32_t year
) const
433 int32_t yearLength
= handleGetYearLength(year
);
435 if (yearLength
> 380) {
436 yearLength
-= 30; // Subtract length of leap month.
441 switch (yearLength
) {
449 //throw new RuntimeException("Illegal year length " + yearLength + " in year " + year);
456 * Determine whether a given Hebrew year is a leap year
458 * The rule here is that if (year % 19) == 0, 3, 6, 8, 11, 14, or 17.
459 * The formula below performs the same test, believe it or not.
461 UBool
HebrewCalendar::isLeapYear(int32_t year
) {
462 //return (year * 12 + 17) % 19 >= 12;
463 int32_t x
= (year
*12 + 17) % 19;
464 return x
>= ((x
< 0) ? -7 : 12);
467 int32_t HebrewCalendar::monthsInYear(int32_t year
) {
468 return isLeapYear(year
) ? 13 : 12;
471 //-------------------------------------------------------------------------
472 // Calendar framework
473 //-------------------------------------------------------------------------
478 int32_t HebrewCalendar::handleGetLimit(UCalendarDateFields field
, ELimitType limitType
) const {
479 return LIMITS
[field
][limitType
];
483 * Returns the length of the given month in the given year
486 int32_t HebrewCalendar::handleGetMonthLength(int32_t extendedYear
, int32_t month
) const {
490 // These two month lengths can vary
491 return MONTH_LENGTH
[month
][yearType(extendedYear
)];
494 // The rest are a fixed length
495 return MONTH_LENGTH
[month
][0];
500 * Returns the number of days in the given Hebrew year
503 int32_t HebrewCalendar::handleGetYearLength(int32_t eyear
) const {
504 UErrorCode status
= U_ZERO_ERROR
;
505 return startOfYear(eyear
+1, status
) - startOfYear(eyear
, status
);
508 //-------------------------------------------------------------------------
509 // Functions for converting from milliseconds to field values
510 //-------------------------------------------------------------------------
513 * Subclasses may override this method to compute several fields
514 * specific to each calendar system. These are:
521 * <li>EXTENDED_YEAR</ul>
523 * Subclasses can refer to the DAY_OF_WEEK and DOW_LOCAL fields,
524 * which will be set when this method is called. Subclasses can
525 * also call the getGregorianXxx() methods to obtain Gregorian
526 * calendar equivalents for the given Julian day.
528 * <p>In addition, subclasses should compute any subclass-specific
529 * fields, that is, fields from BASE_FIELD_COUNT to
530 * getFieldCount() - 1.
533 void HebrewCalendar::handleComputeFields(int32_t julianDay
, UErrorCode
&status
) {
534 int32_t d
= julianDay
- 347997;
535 double m
= ((d
* (double)DAY_PARTS
)/ (double) MONTH_PARTS
); // Months (approx)
536 int32_t year
= (int32_t)( ((19. * m
+ 234.) / 235.) + 1.); // Years (approx)
537 int32_t ys
= startOfYear(year
, status
); // 1st day of year
538 int32_t dayOfYear
= (d
- ys
);
540 // Because of the postponement rules, it's possible to guess wrong. Fix it.
541 while (dayOfYear
< 1) {
543 ys
= startOfYear(year
, status
);
544 dayOfYear
= (d
- ys
);
547 // Now figure out which month we're in, and the date within that month
548 int32_t type
= yearType(year
);
549 UBool isLeap
= isLeapYear(year
);
552 while (dayOfYear
> ( isLeap
? LEAP_MONTH_START
[month
][type
] : MONTH_START
[month
][type
] ) ) {
556 int dayOfMonth
= dayOfYear
- (isLeap
? LEAP_MONTH_START
[month
][type
] : MONTH_START
[month
][type
]);
558 internalSet(UCAL_ERA
, 0);
559 internalSet(UCAL_YEAR
, year
);
560 internalSet(UCAL_EXTENDED_YEAR
, year
);
561 internalSet(UCAL_MONTH
, month
);
562 internalSet(UCAL_DAY_OF_MONTH
, dayOfMonth
);
563 internalSet(UCAL_DAY_OF_YEAR
, dayOfYear
);
566 //-------------------------------------------------------------------------
567 // Functions for converting from field values to milliseconds
568 //-------------------------------------------------------------------------
573 int32_t HebrewCalendar::handleGetExtendedYear() {
575 if (newerField(UCAL_EXTENDED_YEAR
, UCAL_YEAR
) == UCAL_EXTENDED_YEAR
) {
576 year
= internalGet(UCAL_EXTENDED_YEAR
, 1); // Default to year 1
578 year
= internalGet(UCAL_YEAR
, 1); // Default to year 1
584 * Return JD of start of given month/year.
587 int32_t HebrewCalendar::handleComputeMonthStart(int32_t eyear
, int32_t month
, UBool
/*useMonth*/) const {
588 UErrorCode status
= U_ZERO_ERROR
;
589 // Resolve out-of-range months. This is necessary in order to
590 // obtain the correct year. We correct to
591 // a 12- or 13-month year (add/subtract 12 or 13, depending
592 // on the year) but since we _always_ number from 0..12, and
593 // the leap year determines whether or not month 5 (Adar 1)
594 // is present, we allow 0..12 in any given year.
596 month
+= monthsInYear(--eyear
);
598 // Careful: allow 0..12 in all years
600 month
-= monthsInYear(eyear
++);
603 int32_t day
= startOfYear(eyear
, status
);
605 if(U_FAILURE(status
)) {
610 if (isLeapYear(eyear
)) {
611 day
+= LEAP_MONTH_START
[month
][yearType(eyear
)];
613 day
+= MONTH_START
[month
][yearType(eyear
)];
617 return (int) (day
+ 347997);
621 HebrewCalendar::inDaylightTime(UErrorCode
& status
) const
623 // copied from GregorianCalendar
624 if (U_FAILURE(status
) || !getTimeZone().useDaylightTime())
627 // Force an update of the state of the Calendar.
628 ((HebrewCalendar
*)this)->complete(status
); // cast away const
630 return (UBool
)(U_SUCCESS(status
) ? (internalGet(UCAL_DST_OFFSET
) != 0) : FALSE
);
634 const UDate
HebrewCalendar::fgSystemDefaultCentury
= DBL_MIN
;
635 const int32_t HebrewCalendar::fgSystemDefaultCenturyYear
= -1;
637 UDate
HebrewCalendar::fgSystemDefaultCenturyStart
= DBL_MIN
;
638 int32_t HebrewCalendar::fgSystemDefaultCenturyStartYear
= -1;
641 UBool
HebrewCalendar::haveDefaultCentury() const
646 UDate
HebrewCalendar::defaultCenturyStart() const
648 return internalGetDefaultCenturyStart();
651 int32_t HebrewCalendar::defaultCenturyStartYear() const
653 return internalGetDefaultCenturyStartYear();
657 HebrewCalendar::internalGetDefaultCenturyStart() const
659 // lazy-evaluate systemDefaultCenturyStart
663 needsUpdate
= (fgSystemDefaultCenturyStart
== fgSystemDefaultCentury
);
667 initializeSystemDefaultCentury();
670 // use defaultCenturyStart unless it's the flag value;
671 // then use systemDefaultCenturyStart
673 return fgSystemDefaultCenturyStart
;
677 HebrewCalendar::internalGetDefaultCenturyStartYear() const
679 // lazy-evaluate systemDefaultCenturyStartYear
683 needsUpdate
= (fgSystemDefaultCenturyStart
== fgSystemDefaultCentury
);
687 initializeSystemDefaultCentury();
690 // use defaultCenturyStart unless it's the flag value;
691 // then use systemDefaultCenturyStartYear
693 return fgSystemDefaultCenturyStartYear
;
697 HebrewCalendar::initializeSystemDefaultCentury()
699 // initialize systemDefaultCentury and systemDefaultCenturyYear based
700 // on the current time. They'll be set to 80 years before
702 // No point in locking as it should be idempotent.
703 if (fgSystemDefaultCenturyStart
== fgSystemDefaultCentury
)
705 UErrorCode status
= U_ZERO_ERROR
;
706 HebrewCalendar
calendar(Locale("@calendar=hebrew"),status
);
707 if (U_SUCCESS(status
))
709 calendar
.setTime(Calendar::getNow(), status
);
710 calendar
.add(UCAL_YEAR
, -80, status
);
711 UDate newStart
= calendar
.getTime(status
);
712 int32_t newYear
= calendar
.get(UCAL_YEAR
, status
);
715 fgSystemDefaultCenturyStart
= newStart
;
716 fgSystemDefaultCenturyStartYear
= newYear
;
719 // We have no recourse upon failure unless we want to propagate the failure
724 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(HebrewCalendar
);
728 #endif // UCONFIG_NO_FORMATTING