3232
3333package org .opensearch .script ;
3434
35- import org .joda .time .DateTime ;
3635import org .opensearch .common .SuppressForbidden ;
37- import org .opensearch .common .SuppressLoggerChecks ;
38- import org .opensearch .common .logging .DeprecationLogger ;
3936import org .opensearch .common .time .DateFormatter ;
40- import org .opensearch .common .time .DateFormatters ;
41- import org .opensearch .common .time .DateUtils ;
4237
43- import java .security .AccessController ;
44- import java .security .PrivilegedAction ;
4538import java .time .DayOfWeek ;
4639import java .time .Instant ;
4740import java .time .LocalDate ;
5548import java .time .chrono .ChronoZonedDateTime ;
5649import java .time .chrono .Chronology ;
5750import java .time .format .DateTimeFormatter ;
58- import java .time .temporal .ChronoField ;
5951import java .time .temporal .Temporal ;
6052import java .time .temporal .TemporalAccessor ;
6153import java .time .temporal .TemporalAdjuster ;
6456import java .time .temporal .TemporalQuery ;
6557import java .time .temporal .TemporalUnit ;
6658import java .time .temporal .ValueRange ;
67- import java .util .Locale ;
6859import java .util .Objects ;
6960
7061/**
@@ -80,23 +71,6 @@ public class JodaCompatibleZonedDateTime
8071 TemporalAccessor {
8172
8273 private static final DateFormatter DATE_FORMATTER = DateFormatter .forPattern ("strict_date_time" );
83- private static final DeprecationLogger deprecationLogger = DeprecationLogger .getLogger (JodaCompatibleZonedDateTime .class );
84-
85- private static void logDeprecated (String key , String message , Object ... params ) {
86- AccessController .doPrivileged (new PrivilegedAction <Void >() {
87- @ SuppressLoggerChecks (reason = "safely delegates to logger" )
88- @ Override
89- public Void run () {
90- deprecationLogger .deprecate (key , message , params );
91- return null ;
92- }
93- });
94- }
95-
96- private static void logDeprecatedMethod (String oldMethod , String newMethod ) {
97- logDeprecated (oldMethod , "Use of the joda time method [{}] is deprecated. Use [{}] instead." , oldMethod , newMethod );
98- }
99-
10074 private ZonedDateTime dt ;
10175
10276 public JodaCompatibleZonedDateTime (Instant instant , ZoneId zone ) {
@@ -427,120 +401,7 @@ public ZonedDateTime withZoneSameInstant(ZoneId zone) {
427401 return dt .withZoneSameInstant (zone );
428402 }
429403
430- @ Deprecated
431- public long getMillis () {
432- logDeprecatedMethod ("getMillis()" , "toInstant().toEpochMilli()" );
433- return dt .toInstant ().toEpochMilli ();
434- }
435-
436- @ Deprecated
437- public int getCenturyOfEra () {
438- logDeprecatedMethod ("getCenturyOfEra()" , "get(ChronoField.YEAR_OF_ERA) / 100" );
439- return dt .get (ChronoField .YEAR_OF_ERA ) / 100 ;
440- }
441-
442- @ Deprecated
443- public int getEra () {
444- logDeprecatedMethod ("getEra()" , "get(ChronoField.ERA)" );
445- return dt .get (ChronoField .ERA );
446- }
447-
448- @ Deprecated
449- public int getHourOfDay () {
450- logDeprecatedMethod ("getHourOfDay()" , "getHour()" );
451- return dt .getHour ();
452- }
453-
454- @ Deprecated
455- public int getMillisOfDay () {
456- logDeprecatedMethod ("getMillisOfDay()" , "get(ChronoField.MILLI_OF_DAY)" );
457- return dt .get (ChronoField .MILLI_OF_DAY );
458- }
459-
460- @ Deprecated
461- public int getMillisOfSecond () {
462- logDeprecatedMethod ("getMillisOfSecond()" , "get(ChronoField.MILLI_OF_SECOND)" );
463- return dt .get (ChronoField .MILLI_OF_SECOND );
464- }
465-
466- @ Deprecated
467- public int getMinuteOfDay () {
468- logDeprecatedMethod ("getMinuteOfDay()" , "get(ChronoField.MINUTE_OF_DAY)" );
469- return dt .get (ChronoField .MINUTE_OF_DAY );
470- }
471-
472- @ Deprecated
473- public int getMinuteOfHour () {
474- logDeprecatedMethod ("getMinuteOfHour()" , "getMinute()" );
475- return dt .getMinute ();
476- }
477-
478- @ Deprecated
479- public int getMonthOfYear () {
480- logDeprecatedMethod ("getMonthOfYear()" , "getMonthValue()" );
481- return dt .getMonthValue ();
482- }
483-
484- @ Deprecated
485- public int getSecondOfDay () {
486- logDeprecatedMethod ("getSecondOfDay()" , "get(ChronoField.SECOND_OF_DAY)" );
487- return dt .get (ChronoField .SECOND_OF_DAY );
488- }
489-
490- @ Deprecated
491- public int getSecondOfMinute () {
492- logDeprecatedMethod ("getSecondOfMinute()" , "getSecond()" );
493- return dt .getSecond ();
494- }
495-
496- @ Deprecated
497- public int getWeekOfWeekyear () {
498- logDeprecatedMethod ("getWeekOfWeekyear()" , "get(DateFormatters.WEEK_FIELDS_ROOT.weekOfWeekBasedYear())" );
499- return dt .get (DateFormatters .WEEK_FIELDS_ROOT .weekOfWeekBasedYear ());
500- }
501-
502- @ Deprecated
503- public int getWeekyear () {
504- logDeprecatedMethod ("getWeekyear()" , "get(DateFormatters.WEEK_FIELDS_ROOT.weekBasedYear())" );
505- return dt .get (DateFormatters .WEEK_FIELDS_ROOT .weekBasedYear ());
506- }
507-
508- @ Deprecated
509- public int getYearOfCentury () {
510- logDeprecatedMethod ("getYearOfCentury()" , "get(ChronoField.YEAR_OF_ERA) % 100" );
511- return dt .get (ChronoField .YEAR_OF_ERA ) % 100 ;
512- }
513-
514- @ Deprecated
515- public int getYearOfEra () {
516- logDeprecatedMethod ("getYearOfEra()" , "get(ChronoField.YEAR_OF_ERA)" );
517- return dt .get (ChronoField .YEAR_OF_ERA );
518- }
519-
520- @ Deprecated
521- public String toString (String format ) {
522- logDeprecatedMethod ("toString(String)" , "a DateTimeFormatter" );
523- // TODO: replace with bwc formatter
524- return new DateTime (dt .toInstant ().toEpochMilli (), DateUtils .zoneIdToDateTimeZone (dt .getZone ())).toString (format );
525- }
526-
527- @ Deprecated
528- public String toString (String format , Locale locale ) {
529- logDeprecatedMethod ("toString(String,Locale)" , "a DateTimeFormatter" );
530- // TODO: replace with bwc formatter
531- return new DateTime (dt .toInstant ().toEpochMilli (), DateUtils .zoneIdToDateTimeZone (dt .getZone ())).toString (format , locale );
532- }
533-
534404 public DayOfWeek getDayOfWeekEnum () {
535405 return dt .getDayOfWeek ();
536406 }
537-
538- @ Deprecated
539- public int getDayOfWeek () {
540- logDeprecated (
541- "getDayOfWeek()" ,
542- "The return type of [getDayOfWeek()] will change to an enum in 7.0. Use getDayOfWeekEnum().getValue()."
543- );
544- return dt .getDayOfWeek ().getValue ();
545- }
546407}
0 commit comments