mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2024-12-12 00:35:41 +01:00
7 lines
8.7 KiB
Lua
7 lines
8.7 KiB
Lua
|
-- Penlight 1.11.0-1 | /lua/pl/Date.lua | https://github.com/lunarmodules/Penlight | License: MIT | Minified using https://www.npmjs.com/package/luamin/v/1.0.4
|
||
|
-- Copyright (C) 2009-2016 Steve Donovan, David Manura.
|
||
|
-- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||
|
-- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||
|
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||
|
local a=require'pl.class'local b,c=os.time,os.date;local d=require'pl.stringx'local e=require'pl.utils'local f,g=e.assert_arg,e.assert_string;e.raise_deprecation{source="Penlight "..e._VERSION,message="the 'Date' module is deprecated, see https://github.com/lunarmodules/Penlight/issues/285",version_removed="2.0.0",version_deprecated="1.9.2"}local h=a()h.Format=a()function h:_init(i,...)local j;local k=select('#',...)if k>2 then local l={...}local m=i;i={year=m,month=l[1],day=l[2],hour=l[3],min=l[4],sec=l[5]}end;if k==1 then self.utc=select(1,...)==true end;if i==nil or i=='utc'then j=b()self.utc=i=='utc'elseif type(i)=='number'then j=i;if self.utc==nil then self.utc=true end elseif type(i)=='table'then if getmetatable(i)==h then j=i.time;self.utc=i.utc else if not(i.year and i.month)then local n=c('*t')if not i.year and not i.month and not i.day then i.year=n.year;i.month=n.month;i.day=n.day else i.year=i.year or n.year;i.month=i.month or(i.day and n.month or 1)i.day=i.day or 1 end end;i.day=i.day or 1;j=b(i)end else error("bad type for Date constructor: "..type(i),2)end;self:set(j)end;function h:set(i)self.time=i;if self.utc then self.tab=c('!*t',i)else self.tab=c('*t',i)end end;function h.tzone(o)if o==nil then o=b()elseif type(o)=="table"then if getmetatable(o)==h then o=o.time else o=h(o).time end end;local p=c('!*t',o)local q=c('*t',o)q.isdst=false;return os.difftime(b(q),b(p))end;function h:toUTC()local r=h(self)if not self.utc then r.utc=true;r:set(r.time)end;return r end;function h:toLocal()local r=h(self)if self.utc then r.utc=false;r:set(r.time)end;return r end;for s,t in ipairs{'year','month','day','hour','min','sec','yday'}do h[t]=function(self,u)if u then f(1,u,"number")self.tab[t]=u;self:set(b(self.tab))return self else return self.tab[t]end end end;function h:weekday_name(v)return c(v and'%A'or'%a',self.time)end;function h:month_name(v)return c(v and'%B'or'%b',self.time)end;function h:is_weekend()return self.tab.wday==1 or self.tab.wday==7 end;function h:add(i)local w=self.tab.isdst;local x,u=next(i)self.tab[x]=self.tab[x]+u;self:set(b(self.tab))if w~=self.tab.isdst then self.tab.hour=self.tab.hour-(w and 1 or-1)self:set(b(self.tab))end;return self end;function h:last_day()local y=28;local z=self.tab.month;while self.tab.month==z do y=y+1;self:add{day=1}end;self:add{day=-1}return self end;function h:diff(A)local B=self.time-A.time;if B<0 then error("date difference is negative!",2)end;return h.Interval(B)end;function h:__tostring()local C='%Y-%m-%dT%H:%M:%S'if self.utc then C="!"..C end;local i=c(C,self.time)if self.utc then return i..'Z'else local D=self:tzone()if D==0 then return i..'Z'end;local E=D>0 and'+'or'-'local F=math.ceil(D/3600)local z=D%3600/60;if z==0 then return i..('%s%02d'):format(E,F)else return i..('%s%02d:%02d'):format(E,F,z)end end end;function h:__eq(A)return self.time==A.time end;function h:__lt(A)return self.time<A.time end;h.__sub=h.diff;function h:__add(A)local G=h(self)if h.Interval:class_of(A)then A={sec=A.time}end;G:add(A)return G end;h.Interval=a(h)function h.Interval:_init(i)self:set(i)end;function h.Interval:set(i)self.time=i;self.tab=c('!*t',self.time)end;local function H(I)if I>1 then return's 'else return' 'end end;function h.Interval:__tostring()local i,J=self.tab,''local K,z,y=i.year-1970,i.month-1,i.day-1;if K>0 then J=J..K..' year'..H(K)end;if z>0 then J=J..z..' month'..H(z)end;if y>0 then J=J..y..' day'..H(y)end;if K==0 and z==0 then local F=i.hour;if F>0 then J=J..F..' hour'..H(F)end;if i.min>0 then J=J..i.min..' min 'end;if i.sec>0 then J=J..i.sec..' sec 'end end;if J==''then J='zero'end;return J end;local L={d={'day',{true,true}},y={'year',{false,true,false,true}},m={'month',{true,true}},H={'hour',{true,true}},M={'min',{true,true}},S={'sec',{true,true}}}function h.Format:_init(C)if not C then self.fmt='%Y-%m-%d %H:%M:%S'self.outf=self.fmt;self.plain=true;return end;local M=table.insert;local N,O,P,Q='\001','\002','\003','\004'local R,S={},{}local T,U={},{}local V=1;while V<#C do local W=C:sub(V,V)local X=L[W]if X then if S[W]then error("field appeared twice: "..W,
|