Skip to content

Instantly share code, notes, and snippets.

View pithu's full-sized avatar

Philipp Thuerwaechter pithu

View GitHub Profile
import java.time.*
// import org.threeten.bp.*
def data_dst_samples = [
// overlap
['2017-11-05T01:00:00-07:00[America/Los_Angeles]', '2017-11-05T08:00:00Z'],
['2017-11-05T01:00:00-08:00[America/Los_Angeles]', '2017-11-05T08:00:00Z'],
['2017-11-05T02:00:00-08:00[America/Los_Angeles]', '2017-11-05T10:00:00Z'],
['2016-11-06T01:00-04:00[America/New_York]', '2016-11-06T05:00:00Z'],
@pithu
pithu / MomentZoneRules.js
Last active June 2, 2016 07:51
Implement a threeten ZoneRegion by a MomentZoneRules wrapper
import {LocalDate, DayOfWeek, TemporalAdjusters, Instant, ZoneId, ZoneOffset, ZonedDateTime, LocalTime} from 'js-joda'
import {tz} from 'moment-timezone'
class MomentZoneRules {
constructor(tz) {
this.untils = tz.untils;
// localUntils is an array taken from original utc untils, modified by the reverse of the maximum (of actual, previous) offset
// thus, if you take the epochMillis of a LocalDateTime interpreted at UTC and binsearch it here,
// you should find the index of the transition, that is either unique or is before the transition in case of gap/overlap
this.localUntils = tz.untils.map((v, i) => v - Math.min(tz.offsets[i], tz.offsets[Math.max(0, i - 1)]) * 60000);