import{_ as e,o as t,p as a,w as r,k as s,t as n,C as o,b as l,d,i as h,f as u}from"./index-2PZN6pGH.js";import{_ as i}from"./uni-card.CpdfOoXJ.js";import{_ as f}from"./uni-section.BISPxi99.js";function c(e,t=2){for(e+="";e.length<t;)e="0"+e;return e.slice(-t)}const m={yyyy:e=>c(e.year,4),yy:e=>c(e.year),MM:e=>c(e.month),M:e=>e.month,dd:e=>c(e.day),d:e=>e.day,hh:e=>c(e.hour),h:e=>e.hour,mm:e=>c(e.minute),m:e=>e.minute,ss:e=>c(e.second),s:e=>e.second,SSS:e=>c(e.millisecond,3),S:e=>e.millisecond};function y(e){return e instanceof Date?e:"string"==typeof e?e.indexOf("T")>-1?new Date(e):new Date(e.replace(/-/g,"/")):new Date(e)}function p(e,{locale:t="zh",threshold:a=[6e4,36e5],format:r="yyyy/MM/dd hh:mm:ss"}){if("-"===e)return e;if(!e&&0!==e)return"";const s={zh:{year:"年",month:"月",day:"天",hour:"小时",minute:"分钟",second:"秒",ago:"前",later:"后",justNow:"刚刚",soon:"马上",template:"{num}{unit}{suffix}"},en:{year:"year",month:"month",day:"day",hour:"hour",minute:"minute",second:"second",ago:"ago",later:"later",justNow:"just now",soon:"soon",template:"{num} {unit} {suffix}"}},n=s[t]||s.zh;let o,l,d=y(e),h=d.getTime()-Date.now(),u=Math.abs(h);if(u<a[0])return h<0?n.justNow:n.soon;if(u>=a[1])return function(e,t="yyyy/MM/dd hh:mm:ss"){if(!e&&0!==e)return"";const a={year:(e=y(e)).getFullYear(),month:e.getMonth()+1,day:e.getDate(),hour:e.getHours(),minute:e.getMinutes(),second:e.getSeconds(),millisecond:e.getMilliseconds()},r=/yyyy|yy|MM|M|dd|d|hh|h|mm|m|ss|s|SSS|SS|S/;let s=!0,n=t;for(;s;)s=!1,n=n.replace(r,(function(e){return s=!0,m[e](a)}));return n}(d,r);let i=n.later;h<0&&(i=n.ago,h=-h);const f=Math.floor(h/1e3),c=Math.floor(f/60),p=Math.floor(c/60),g=Math.floor(p/24),M=Math.floor(g/30),w=Math.floor(M/12);switch(!0){case w>0:o=w,l=n.year;break;case M>0:o=M,l=n.month;break;case g>0:o=g,l=n.day;break;case p>0:o=p,l=n.hour;break;case c>0:o=c,l=n.minute;break;default:o=f,l=n.second}return"en"===t&&(1===o?o="a":l+="s"),n.template.replace(/{\s*num\s*}/g,o+"").replace(/{\s*unit\s*}/g,l).replace(/{\s*suffix\s*}/g,i)}const g=e({name:"uniDateformat",props:{date:{type:[Object,String,Number],default:()=>"-"},locale:{type:String,default:"zh"},threshold:{type:Array,default:()=>[0,0]},format:{type:String,default:"yyyy/MM/dd hh:mm:ss"},refreshRate:{type:[Number,String],default:0}},data:()=>({refreshMark:0}),computed:{dateShow(){return this.refreshMark,p(this.date,{locale:this.locale,threshold:this.threshold,format:this.format})}},watch:{refreshRate:{handler(){this.setAutoRefresh()},immediate:!0}},methods:{refresh(){this.refreshMark++},setAutoRefresh(){clearInterval(this.refreshInterval),this.refreshRate&&(this.refreshInterval=setInterval((()=>{this.refresh()}),parseInt(this.refreshRate)))}}},[["render",function(e,l,d,h,u,i){const f=o;return t(),a(f,null,{default:r((()=>[s(n(i.dateShow),1)])),_:1})}]]);const M=e({data:()=>({now:Date.now()}),methods:{}},[["render",function(e,n,c,m,y,p){const M=o,w=l(d("uni-card"),i),S=l(d("uni-dateformat"),g),b=h,_=l(d("uni-section"),f);return t(),a(b,null,{default:r((()=>[u(w,{"is-shadow":!1,"is-full":""},{default:r((()=>[u(M,{class:"uni-h6"},{default:r((()=>[s("日期格式化组件，通常用于需要展示友好的日期格式的场景。")])),_:1})])),_:1}),u(_,{title:"基础用法",type:"line",padding:""},{default:r((()=>[u(b,{class:"example-body"},{default:r((()=>[u(S,{date:y.now-72e5},null,8,["date"]),u(S,{date:"2020/12/12"})])),_:1})])),_:1}),u(_,{title:"设置阈值",subTitle:"阈值用于控制什么时候显示刚刚|马上，什么时候显示xx分钟前|xx分钟后",type:"line",padding:""},{default:r((()=>[u(b,{class:"example-body"},{default:r((()=>[u(S,{date:y.now-3e4,threshold:[0,36e5]},null,8,["date"]),u(S,{date:y.now-3e4,threshold:[0,0]},null,8,["date"])])),_:1})])),_:1}),u(_,{title:"使用英文",type:"line",padding:""},{default:r((()=>[u(b,{class:"example-body"},{default:r((()=>[u(S,{date:y.now-12e5,threshold:[6e4,36e5],locale:"en"},null,8,["date"]),u(S,{date:y.now-3e4,threshold:[6e4,36e5],locale:"en"},null,8,["date"]),u(S,{date:y.now-8e4,threshold:[6e4,36e5],locale:"en"},null,8,["date"])])),_:1})])),_:1})])),_:1})}],["__scopeId","data-v-ae9d12bc"]]);export{M as default};
