private void calculateOffset ( long currentTime , RestRequestResult result ) { // Double-checked locking for better performance if ( ( api . getTimeOffset ( ) != null ) || ( result == null ) || ( result . getResponse ( ) == null ) ) { return ; } synchronized ( api ) { if ( api . getTimeOffset ( ) == null ) { // Discord sends the date in their header in the format RFC_1123_DATE_TIME // We use this header to calculate a possible offset between our local time and the discord time String date = result . getResponse ( ) . header ( "Date" ) ; if ( date != null ) { long discordTimestamp = OffsetDateTime . parse ( date , DateTimeFormatter . RFC_1123_DATE_TIME ) . toInstant ( ) . toEpochMilli ( ) ; api . setTimeOffset ( ( discordTimestamp - currentTime ) ) ; logger . debug ( "Calculated an offset of {} to the Discord time." , api :: getTimeOffset ) ; } } } }
Calculates the offset of the local time and discord s time .