PageSourceSearch

https://www.pldi21.org/static/js/modules/timeZones.js

js pldi21.org collected 2026-10-02 03:41:19 UTC 5,812 bytes, 231 lines download raw bytes

1/* eslint no-var: "off", vars-on-top: "off" */
2
3// ////
4
5// A Cookie to stash the current time zone.
6// Use this *everywhere* you need to convert dates.
7
8function setCurrentTimeZone(tz) {
9  if (tz === "Local") {
10    tz = moment.tz.guess();
11  }
12  window.localStorage.setItem("miniconf-timezone", tz);
13}
14
15var cachedTimeZone;
16
17function getCurrentTimeZone() {
18  if (cachedTimeZone) {
19    return cachedTimeZone;
20  }
21  const tz = getUrlParameter("tz");
22  if (tz != null && tz !== "") {
23    setCurrentTimeZone(tz);
24    cachedTimeZone = tz;
25    return cachedTimeZone;
26  }
27  const cookie = window.localStorage.getItem("miniconf-timezone");
28
29  if (cookie != null && cookie !== "") {
30    cachedTimeZone = cookie;
31    return cachedTimeZone;
32  }
33  const guess = moment.tz.guess();
34  setCurrentTimeZone(guess);
35  cachedTimeZone = guess;
36  return cachedTimeZone;
37}
38
39var fakeTime; // Fake Time For Debugging -- set to use it everywhere
40
41function currentTime() {
42  if (fakeTime) {
43    return fakeTime.format();
44  }
45  return moment().format();
46}
47
48// Convenience function to get the current time as a moment in the current
49// time zone.
50function currentTimeMoment() {
51  return moment.utc(currentTime()).tz(getCurrentTimeZone());
52}
53
54// Convenience function to get the current time as a moment in GMT.
55function currentTimeMomentGMT() {
56  return moment.utc(currentTime()).tz("GMT");
57}
58
59function gmtSuffixForMoment(atime) {
60  var t = atime.format("Z");
61  if (t.endsWith(":00")) {
62    t = t.slice(0, -3);
63  }
64  if (t.startsWith("0")) {
65    t = t.slice(1);
66  } else if (t.startsWith("-0")) {
67    t = `-${t.slice(2)}`;
68  }
69  return `GMT${t}`;
70}
71
72function gmtSuffixForCurrentMoment() {
73  return gmtSuffixForMoment(currentTimeMoment());
74}
75
76// / For Debugging -- matches code in base.html.
77
78function updateFakeTime() {
79  const element = document.getElementById("fakeTimeId");
80  if (element) {
81    element.innerHTML = `${currentTimeMoment().format(
82      "llll"
83    )} <br> UTC: ${currentTime()} `;
84  }
85}
86
87// Call this to initialize the fake time to t.
88function setFakeTime(t) {
89  fakeTime = moment.utc(t);
90  updateFakeTime();
91}
92
93// Step fake time by number of minutes
94function stepTime(min) {
95  fakeTime = fakeTime.add({ minutes: min });
96  updateFakeTime();
97}
98
99function fastForward() {
100  setInterval(() => {
101    stepTime(1);
102  }, 1000);
103}
104
105// /// From Neurips /////
106function getTimezone() {
107  return getCurrentTimeZone();
108}
109
110function formatDate(element) {
111  const current_tz = getTimezone();
112  const text = element.text().trim();
113  const atime = moment(text).clone().tz(current_tz);
114  const gmtSuffix = `&nbsp; ${gmtSuffixForMoment(atime)}`;
115  const str = atime.format("ddd HH:mm");
116  element.html(`${str} ${gmtSuffix}`);
117}
118
119function formatDateTime(element) {
120  const current_tz = getTimezone();
121  const text = element.text().trim();
122  const atime = moment(text).clone().tz(current_tz);
123  const gmtSuffix = `&nbsp; ${gmtSuffixForMoment(atime)}`;
124  const str = atime.format("ddd HH:mm");
125  element.html(`${str} ${gmtSuffix}`);
126}
127
128function formatTimeSpan(element, includeGMT) {
129  const current_tz = getTimezone();
130  const parts = element.text().trim().split(" - ");
131  // console.log(parts, "--- parts", element.text());
132  const start = parts[0].trim();
133  const end = parts[1].trim();
134
135  const starttime = moment(start).clone().tz(current_tz);
136  const endtime = moment(end).clone().tz(current_tz);
137
138  if (includeGMT) {
139    gmtSuffix = `&nbsp; ${gmtSuffixForMoment(starttime)}`;
140  } else {
141    gmtSuffix = "";
142  }
143
144  // if(starttime.diff(endtime, "days") <= 0) // Making difference between the "D" numbers because the diff function
145  // seems like not considering the timezone
146  if (starttime.format("D") === endtime.format("D")) {
147    element.html(
148      `${starttime.format("ddd HH:mm")} &ndash; ${endtime.format(
149        "HH:mm"
150      )} ${gmtSuffix}`
151    );
152    // element.html(
153    //   `${starttime.format("HH:mm")} &ndash; ${endtime.format(
154    //     "HH:mm ~"
155    //   )} ${gmtSuffix}`
156    // );
157  } else {
158    element.html(
159      `${starttime.format("ddd HH:mm")} &ndash; ${endtime.format(
160        "ddd HH:mm"
161      )} ${gmtSuffix}`
162    );
163  }
164}
165
166function formatTimeSpanWithDays(element, includeGMT) {
167  const current_tz = getTimezone();
168  const parts = element.text().trim().split(" - ");
169  const start = parts[0].trim();
170  const end = parts[1].trim();
171
172  const starttime = moment(start).clone().tz(current_tz);
173  const endtime = moment(end).clone().tz(current_tz);
174
175  if (includeGMT) {
176    gmtSuffix = `&nbsp; ${gmtSuffixForMoment(starttime)}`;
177  } else {
178    gmtSuffix = "";
179  }
180
181  element.html(
182    `${starttime.format("ddd HH:mm")} &ndash; ${endtime.format(
183      "ddd HH:mm"
184    )} ${gmtSuffix}`
185  );
186}
187
188function formatTime(element) {
189  const current_tz = getTimezone();
190  const atime = moment(element.text()).clone().tz(current_tz);
191  const gmtSuffix = `&nbsp; ${gmtSuffixForMoment(atime)}`;
192  element.html(`${atime.format("HH:mm")} ${gmtSuffix}`);
193}
194
195function timeZoneStart() {
196  const current_tz = getTimezone();
197  $("#tzCurrent").html(moment().tz(current_tz).format("Z"));
198
199  // find all parseable dates and localize them
200  $(".format-just-date").each((_i, element) => {
201    formatDate($(element));
202  });
203
204  $(".format-date").each((_i, element) => {
205    formatDateTime($(element));
206  });
207
208  $(".format-date-span").each((_i, element) => {
209    formatTimeSpan($(element, true));
210  });
211
212  $(".format-date-span-short").each((_i, element) => {
213    formatTimeSpan($(element), false);
214  });
215
216  $(".format-date-span-with-days").each((_i, element) => {
217    formatTimeSpanWithDays($(element), true);
218  });
219
220  $(".format-date-span-full").each((_i, element) => {
221    formatTimeSpan($(element), true);
222  });
223
224  $(".format-time").each((_i, element) => {
225    formatTime($(element));
226  });
227}
228
229$(document).ready(() => {
230  timeZoneStart();
231});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.