Moved date helper funcs to utils.js
This commit is contained in:
		| @@ -58,6 +58,7 @@ | |||||||
| <script> | <script> | ||||||
|  |  | ||||||
| import { highscoreStatistics } from "@/api"; | import { highscoreStatistics } from "@/api"; | ||||||
|  | import { humanReadableDate, daysAgo } from "@/utils"; | ||||||
| import Wine from "@/ui/Wine"; | import Wine from "@/ui/Wine"; | ||||||
|  |  | ||||||
| export default { | export default { | ||||||
| @@ -92,19 +93,13 @@ export default { | |||||||
|     } |     } | ||||||
|   }, |   }, | ||||||
|   methods: { |   methods: { | ||||||
|  |     humanReadableDate: humanReadableDate, | ||||||
|  |     daysAgo: daysAgo, | ||||||
|     resetFilter() { |     resetFilter() { | ||||||
|       this.highscore = this.highscoreResponse; |       this.highscore = this.highscoreResponse; | ||||||
|       this.highscoreFilter = ''; |       this.highscoreFilter = ''; | ||||||
|       document.getElementsByTagName('input')[0].focus(); |       document.getElementsByTagName('input')[0].focus(); | ||||||
|     }, |     }, | ||||||
|     humanReadableDate(date) { |  | ||||||
|       const options = { year: 'numeric', month: 'long', day: 'numeric' }; |  | ||||||
|       return new Date(date).toLocaleDateString(undefined, options); |  | ||||||
|     }, |  | ||||||
|     daysAgo(date) { |  | ||||||
|       const day = 24 * 60 * 60 * 1000; |  | ||||||
|       return Math.round(Math.abs((new Date() - new Date(date)) / day)); |  | ||||||
|     }, |  | ||||||
|     selectWinner(winner) { |     selectWinner(winner) { | ||||||
|       if (this.selectedWinner != null && this.selectedWinner["name"] == winner["name"]) { |       if (this.selectedWinner != null && this.selectedWinner["name"] == winner["name"]) { | ||||||
|         this.selectedWinner = null; |         this.selectedWinner = null; | ||||||
|   | |||||||
							
								
								
									
										16
									
								
								src/utils.js
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								src/utils.js
									
									
									
									
									
								
							| @@ -7,6 +7,18 @@ const dateString = (date) => { | |||||||
|   return `${ye}-${mo}-${da}` |   return `${ye}-${mo}-${da}` | ||||||
| } | } | ||||||
|  |  | ||||||
| module.exports = { | function humanReadableDate(date) { | ||||||
|   dateString |   const options = { year: 'numeric', month: 'long', day: 'numeric' }; | ||||||
|  |   return new Date(date).toLocaleDateString(undefined, options); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function daysAgo(date) { | ||||||
|  |   const day = 24 * 60 * 60 * 1000; | ||||||
|  |   return Math.round(Math.abs((new Date() - new Date(date)) / day)); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | module.exports = { | ||||||
|  |   dateString, | ||||||
|  |   humanReadableDate, | ||||||
|  |   daysAgo | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user