TIL post around timezones in JS
This commit is contained in:
		
							parent
							
								
									58a39c4e4c
								
							
						
					
					
						commit
						b2c42a8b0c
					
				
							
								
								
									
										17
									
								
								src/_data/blogroll.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								src/_data/blogroll.json
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,17 @@ | ||||
| [ | ||||
|     { | ||||
|         "name": "Robb Knight", | ||||
|         "website": "https://rknight.me", | ||||
|         "rss": "https://rknight.me/subscribe/posts/rss.xml" | ||||
|     }, | ||||
|     { | ||||
|         "name": "Terence Eden", | ||||
|         "website": "https://shkspr.mobi", | ||||
|         "rss": "https://shkspr.mobi/blog/feed/atom/" | ||||
|     }, | ||||
|     { | ||||
|         "name": "Sara Joy", | ||||
|         "website": "https://sarajoy.dev", | ||||
|         "rss": "https://sarajoy.dev/rss.xml" | ||||
|     } | ||||
| ] | ||||
							
								
								
									
										18
									
								
								src/blog/posts/2024/2/why-is-date.parse-weird-in-gmt.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								src/blog/posts/2024/2/why-is-date.parse-weird-in-gmt.md
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,18 @@ | ||||
| --- | ||||
| title: "TIL: Why Date.parse gives unexpected results for GMT" | ||||
| tags: | ||||
|     - Javascript | ||||
|     - TIL | ||||
| --- | ||||
| 
 | ||||
| TL;DR: Timezones are weird | ||||
| 
 | ||||
| Someone posted about this in a Discord server I'm on: Javascript's Date object has a parse function, [Date.parse](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse) that takes a string can converts it to a timestamp. If you give it a non-standard string, in this case `Jan 1, 1970`, it should still parse it. | ||||
| 
 | ||||
| The problem is though, that even though we're in GMT, and `GMT == UTC`, `Date.parse("Jan 1, 1970")` results in a timestamp of `-3600000`, or Dec 31, 1969 23:00:00. If you explicitly add the GMT timezone, it's fine. | ||||
| 
 | ||||
| It turns out that if you omit the timezone, `Date.parse` will use your system timezone - now in my case that's GMT _today_[^1], but if I were to go back to 1970 I'd actually find that I'd be in BST. This is because the government [experimented with scrapping daylight savings](https://www.rmg.co.uk/stories/topics/uk-time-british-summer-time-bst-daylight-saving). So, when you parse that specific date, your timezone is actually `UTC+1`. | ||||
| 
 | ||||
| [^1]: Obviously this only breaks in the UK | ||||
| 
 | ||||
| 
 | ||||
							
								
								
									
										13
									
								
								src/blogroll.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								src/blogroll.html
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,13 @@ | ||||
| --- | ||||
| title: Blogroll | ||||
| layout: page.njk | ||||
| --- | ||||
| 
 | ||||
| <ul> | ||||
| {% for blog in blogroll %} | ||||
|     <li> | ||||
|         {{ blog.name }} | ||||
|     </li> | ||||
| {% endfor %} | ||||
| </ul> | ||||
| 
 | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user