UNPKG

azure-devops-ui

Version:

React components for building web UI in Azure DevOps

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