UNPKG

azure-devops-ui

Version:

React components for building web UI in Azure DevOps

1 lines 3.79 kB
import{format}from"../Core/Util/String";import*as PlatformResources from"../Resources.Core";var AgoFormat,LogType,millisecond=1,second=1e3*millisecond,minute=60*second,hour=60*minute,day=24*hour,week=7*day,agoFormatters=(!function(t){t[t.Compact=0]="Compact",t[t.Extended=1]="Extended"}(AgoFormat=AgoFormat||{}),{});function ago(t,e,o,r){var a,m=agoFormatters[r||""],n=(m||(agoFormatters[r||""]=m={}),o=o||new Date,e=e||AgoFormat.Compact,o.getTime()-t.getTime()),i="";return n<2*minute?i=PlatformResources.JustNow:e===AgoFormat.Compact?i=n<59*minute?format(PlatformResources.AgoMinutes,Math.round(n/minute)):o.getDate()===t.getDate()&&o.getMonth()===t.getMonth()&&o.getFullYear()===t.getFullYear()?format(PlatformResources.AgoHours,Math.round(n/hour)):n<week&&o.getDay()!==t.getDay()?((a=new Date).setDate(o.getDate()-1),t.getDate()===a.getDate()?PlatformResources.Yesterday:t.toLocaleString(r,{weekday:"long"})):(o.getFullYear()===t.getFullYear()?(m.ctShortFormat=m.ctShortFormat||new Intl.DateTimeFormat(r,{month:"short",day:"numeric"}),m.ctShortFormat):(m.ctLongFormat=m.ctLongFormat||new Intl.DateTimeFormat(r,{month:"short",year:"numeric",day:"numeric"}),m.ctLongFormat)).format(t):e===AgoFormat.Extended&&(e="",e=o.getDate()===t.getDate()&&o.getMonth()===t.getMonth()&&o.getFullYear()===t.getFullYear()?PlatformResources.Today:n<week&&o.getDay()!==t.getDay()?((a=new Date).setDate(o.getDate()-1),t.getDate()===a.getDate()?PlatformResources.Yesterday:(m.exWeekFormat=m.exWeekFormat||new Intl.DateTimeFormat(r,{weekday:"short"}),m.exWeekFormat.format(t))):(o.getFullYear()===t.getFullYear()?(m.exMonthFormat=m.exMonthFormat||new Intl.DateTimeFormat(r,{month:"short",day:"numeric"}),m.exMonthFormat):(m.exYearFormat=m.exYearFormat||new Intl.DateTimeFormat(r,{month:"short",year:"numeric",day:"numeric"}),m.exYearFormat)).format(t),m.timeFormat=m.timeFormat||new Intl.DateTimeFormat(r,{hour:"numeric",minute:"numeric"}),n=m.timeFormat.format(t),i=format(PlatformResources.DayAtTimeFormat,e,n)),i=i||t.toString()}!function(t){t[t.Full=0]="Full",t[t.Date=1]="Date",t[t.Local=2]="Local"}(LogType=LogType||{});var logFormatters={};function log(t,e,o){var r,a=logFormatters[o||""],m=(a||(logFormatters[o||""]=a={}),"");return e=e||LogType.Full,LogType.Full===e?m=t.toISOString():LogType.Date===e?(a.dayFormatShort=a.dayFormatShort||new Intl.DateTimeFormat(o,{month:"2-digit",day:"2-digit"}),r=a.dayFormatShort.format(t),a.timeFormatShort=a.timeFormatShort||new Intl.DateTimeFormat(o,{hour:"2-digit",minute:"2-digit",hour12:!1,timeZoneName:"short"}),m=r+" "+a.timeFormatShort.format(t)):LogType.Local===e&&(a.timeFormatLong=a.timeFormatLong||new Intl.DateTimeFormat(o,{hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1,timeZoneName:"short"}),m=a.timeFormatLong.format(t)),m=m||t.toString()}function duration(t,e){var o,r,a,e=(e=e||new Date).getTime()-t.getTime();return e<second?PlatformResources.LessThanASecond:e<minute?format(PlatformResources.Seconds,Math.floor(e/second)):(t=Math.floor(e/day),o=Math.floor(e%day/hour),r=Math.floor(e%hour/minute),a=Math.floor(e%minute/second),e<hour?format(PlatformResources.MinutesSeconds,r,a):e<day?format(PlatformResources.HoursMinutesSeconds,o,r,a):format(PlatformResources.DaysHoursMinutes,t,o,r))}var tooltipFormatters={};function tooltipString(t,e,o){var r=tooltipFormatters[e||""];return r||(tooltipFormatters[e||""]=r={}),r.dayFormat=r.dayFormat||new Intl.DateTimeFormat(e,{month:"short",year:"numeric",day:"numeric"}),r.timeFormat=o?new Intl.DateTimeFormat(e,o):r.timeFormat||new Intl.DateTimeFormat(e,{hour:"numeric",minute:"numeric",timeZoneName:"short"}),format(PlatformResources.DayAtTimeFormat,r.dayFormat.format(t),r.timeFormat.format(t))}export{millisecond,second,minute,hour,day,week,AgoFormat,ago,LogType,log,duration,tooltipString};