Skip to content

Commit

Permalink
On review fixed an issue with how aliases are resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
benfortuna committed Apr 27, 2024
1 parent f36f3f7 commit 15d9c74
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
Expand Up @@ -66,7 +66,7 @@ static ZoneId getGlobalZoneId(String tzId) {
ZoneId zoneId = ZoneId.of(tzId, ZONE_ALIASES);
Optional<Map.Entry<String, String>> lookup = ZONE_IDS.entrySet().stream().filter(entry ->
entry.getValue().equals(zoneId.getId())).findFirst();
return lookup.map(mapping -> ZoneId.of(mapping.getKey())).orElseThrow();
return lookup.map(mapping -> ZoneId.of(mapping.getKey())).orElse(zoneId);
}

/**
Expand Down
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2024, Ben Fortuna
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* o Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* o Neither the name of Ben Fortuna nor the names of any other contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/

package net.fortuna.ical4j.model

import spock.lang.Specification

class TimeZoneRegistryTest extends Specification {

def 'test global zone id retrieval'() {
expect: 'matching result'
TimeZoneRegistry.getGlobalZoneId(id) == TimeZoneRegistry.getGlobalZoneId(expectedZoneId)

where:
id | expectedZoneId
'UTC' | 'Etc/UTC'
'Europe/London' | 'Europe/London'
}
}
6 changes: 5 additions & 1 deletion src/test/groovy/net/fortuna/ical4j/model/TimeZoneSpec.groovy
Expand Up @@ -43,6 +43,7 @@ import spock.lang.Unroll
import java.time.LocalDate
import java.time.ZoneId
import java.time.ZoneOffset
import java.util.stream.Collectors

@Slf4j
class TimeZoneSpec extends Specification {
Expand Down Expand Up @@ -217,6 +218,9 @@ class TimeZoneSpec extends Specification {
System.clearProperty('net.fortuna.ical4j.timezone.update.enabled')

where:
alias << ZoneId.getAvailableZoneIds()
alias << getClass().getResourceAsStream('/net/fortuna/ical4j/model/tz.alias').readLines().stream()
.filter(line -> !line.empty && !line.contains('#')).map {
line -> line.split('\\s*=\\s*')[0]
}.collect(Collectors.toList())
}
}

0 comments on commit 15d9c74

Please sign in to comment.