Skip to content

Commit a9ec063

Browse files
committed
fixed timezone placeholder issues
1 parent 4319495 commit a9ec063

2 files changed

Lines changed: 24 additions & 26 deletions

File tree

assets/js/meetup-timezone.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,21 @@
4747

4848
let formatted = format;
4949

50-
// Process replacements in a specific order to avoid conflicts
51-
// Process longer patterns first, then shorter ones
52-
const sortedKeys = Object.keys(replacements).sort((a, b) => b.length - a.length);
53-
54-
for (const key of sortedKeys) {
55-
const value = replacements[key];
56-
// Use a placeholder to avoid replacing already-replaced values
57-
const placeholder = `__PLACEHOLDER_${key}__`;
50+
// Use a unique placeholder pattern that won't conflict with date format characters
51+
// Using Unicode characters that are unlikely to appear in format strings
52+
const placeholderPrefix = '\u{1F4C5}'; // Calendar emoji as unique marker
53+
const placeholders = {};
54+
55+
// First pass: replace format characters with unique placeholders
56+
for (const key in replacements) {
57+
const placeholder = placeholderPrefix + key + placeholderPrefix;
58+
placeholders[placeholder] = replacements[key];
5859
formatted = formatted.split(key).join(placeholder);
5960
}
6061

61-
// Replace all placeholders with actual values
62-
for (const key of sortedKeys) {
63-
const value = replacements[key];
64-
const placeholder = `__PLACEHOLDER_${key}__`;
65-
formatted = formatted.split(placeholder).join(value);
62+
// Second pass: replace placeholders with actual values
63+
for (const placeholder in placeholders) {
64+
formatted = formatted.split(placeholder).join(placeholders[placeholder]);
6665
}
6766

6867
return formatted;

static/js/meetup-timezone.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,21 @@
4747

4848
let formatted = format;
4949

50-
// Process replacements in a specific order to avoid conflicts
51-
// Process longer patterns first, then shorter ones
52-
const sortedKeys = Object.keys(replacements).sort((a, b) => b.length - a.length);
53-
54-
for (const key of sortedKeys) {
55-
const value = replacements[key];
56-
// Use a placeholder to avoid replacing already-replaced values
57-
const placeholder = `__PLACEHOLDER_${key}__`;
50+
// Use a unique placeholder pattern that won't conflict with date format characters
51+
// Using Unicode characters that are unlikely to appear in format strings
52+
const placeholderPrefix = '\u{1F4C5}'; // Calendar emoji as unique marker
53+
const placeholders = {};
54+
55+
// First pass: replace format characters with unique placeholders
56+
for (const key in replacements) {
57+
const placeholder = placeholderPrefix + key + placeholderPrefix;
58+
placeholders[placeholder] = replacements[key];
5859
formatted = formatted.split(key).join(placeholder);
5960
}
6061

61-
// Replace all placeholders with actual values
62-
for (const key of sortedKeys) {
63-
const value = replacements[key];
64-
const placeholder = `__PLACEHOLDER_${key}__`;
65-
formatted = formatted.split(placeholder).join(value);
62+
// Second pass: replace placeholders with actual values
63+
for (const placeholder in placeholders) {
64+
formatted = formatted.split(placeholder).join(placeholders[placeholder]);
6665
}
6766

6867
return formatted;

0 commit comments

Comments
 (0)