mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-19 21:38:05 +01:00
Add CLDR region as a dimension
This commit is contained in:
committed by
Jon Chambers
parent
b280c768a4
commit
3bb4709563
@@ -8,6 +8,7 @@ import com.google.i18n.phonenumbers.NumberParseException;
|
||||
import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
||||
import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat;
|
||||
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import java.time.Clock;
|
||||
import java.time.Duration;
|
||||
import java.time.temporal.ChronoField;
|
||||
@@ -21,6 +22,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class Util {
|
||||
|
||||
@@ -79,10 +81,11 @@ public class Util {
|
||||
else return "0";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getRegion(final String number) {
|
||||
try {
|
||||
final PhoneNumber phoneNumber = PHONE_NUMBER_UTIL.parse(number, null);
|
||||
return PHONE_NUMBER_UTIL.getRegionCodeForNumber(phoneNumber);
|
||||
return StringUtils.defaultIfBlank(PHONE_NUMBER_UTIL.getRegionCodeForNumber(phoneNumber), "ZZ");
|
||||
} catch (final NumberParseException e) {
|
||||
return "ZZ";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user