show time/weekday in tooltip for style entries (#1205)
This commit is contained in:
		
							parent
							
								
									ff63b84489
								
							
						
					
					
						commit
						9d19d61913
					
				|  | @ -140,17 +140,31 @@ Object.assign(t, { | ||||||
|     } |     } | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   formatDate(date) { |   _intl: null, | ||||||
|  |   _intlY: null, | ||||||
|  |   _intlYHM: null, | ||||||
|  |   _intlWYHM: null, | ||||||
|  | 
 | ||||||
|  |   formatDate(date, needsTime) { | ||||||
|     if (!date) { |     if (!date) { | ||||||
|       return ''; |       return ''; | ||||||
|     } |     } | ||||||
|     try { |     try { | ||||||
|  |       const now = new Date(); | ||||||
|       const newDate = new Date(Number(date) || date); |       const newDate = new Date(Number(date) || date); | ||||||
|       const string = newDate.toLocaleDateString([chrome.i18n.getUILanguage(), 'en'], { |       const needsYear = newDate.getYear() !== now.getYear(); | ||||||
|         day: '2-digit', |       const needsWeekDay = needsTime && (now - newDate <= 7 * 24 * 3600e3); | ||||||
|         month: 'short', |       const intlKey = `_intl${needsWeekDay ? 'W' : ''}${needsYear ? 'Y' : ''}${needsTime ? 'HM' : ''}`; | ||||||
|         year: newDate.getYear() === new Date().getYear() ? undefined : '2-digit', |       const intl = t[intlKey] || | ||||||
|       }); |         (t[intlKey] = new Intl.DateTimeFormat([chrome.i18n.getUILanguage(), 'en'], { | ||||||
|  |           day: 'numeric', | ||||||
|  |           month: 'short', | ||||||
|  |           year: needsYear ? '2-digit' : undefined, | ||||||
|  |           hour: needsTime ? 'numeric' : undefined, | ||||||
|  |           minute: needsTime ? '2-digit' : undefined, | ||||||
|  |           weekday: needsWeekDay ? 'long' : undefined, | ||||||
|  |         })); | ||||||
|  |       const string = intl.format(newDate); | ||||||
|       return string === 'Invalid Date' ? '' : string; |       return string === 'Invalid Date' ? '' : string; | ||||||
|     } catch (e) { |     } catch (e) { | ||||||
|       return ''; |       return ''; | ||||||
|  |  | ||||||
|  | @ -23,8 +23,8 @@ const Events = { | ||||||
|     const style = link.closest('.entry').styleMeta; |     const style = link.closest('.entry').styleMeta; | ||||||
|     const ucd = style.usercssData; |     const ucd = style.usercssData; | ||||||
|     link.title = |     link.title = | ||||||
|       `${t('dateInstalled')}: ${t.formatDate(style.installDate) || '—'}\n` + |       `${t('dateInstalled')}: ${t.formatDate(style.installDate, true) || '—'}\n` + | ||||||
|       `${t('dateUpdated')}: ${t.formatDate(style.updateDate) || '—'}\n` + |       `${t('dateUpdated')}: ${t.formatDate(style.updateDate, true) || '—'}\n` + | ||||||
|       (ucd ? `UserCSS, v.${ucd.version}` : ''); |       (ucd ? `UserCSS, v.${ucd.version}` : ''); | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user