Skip to content

Commit

Permalink
update date and excel.
Browse files Browse the repository at this point in the history
  • Loading branch information
dojyorin committed Feb 1, 2024
1 parent e7c9f34 commit a7fd657
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/pure/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ export async function delay(time:number):Promise<number>{
* const format = dtSerial();
* ```
*/
export function dtSerial(date?:Date):string{
export function dtSerial(date?:Date, split?:boolean):string{
const d = date ?? new Date();
const ss = split ? "/" : "";
const sc = split ? ":" : "";

return `${d.getFullYear()}${pad0(d.getMonth() + 1)}${pad0(d.getDate())}${pad0(d.getHours())}${pad0(d.getMinutes())}${pad0(d.getSeconds())}`;
return `${d.getFullYear()}${ss}${pad0(d.getMonth() + 1)}${ss}${pad0(d.getDate())}${split ? " " : ""}${pad0(d.getHours())}${sc}${pad0(d.getMinutes())}${sc}${pad0(d.getSeconds())}`;
}
16 changes: 15 additions & 1 deletion src/pure_ext/excel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {type RawWorkBook, type RawWorkSheet, type RawWorkCell, xlsxcp, set_cptable, xlsxRead, xlsxWrite, xlsxUtil} from "../../deps.pure_ext.ts";
import {deepClone} from "../pure/deep.ts";
import {dtSerial} from "../pure/time.ts";

export type {RawWorkBook, RawWorkSheet, RawWorkCell};

Expand All @@ -19,6 +20,8 @@ export function excelEncodeRaw(book:RawWorkBook, cp?:number, pw?:string):Uint8Ar
const buf = <ArrayBuffer>xlsxWrite(book, {
type: "array",
compression: true,
cellStyles: true,
cellDates: true,
codepage: cp,
password: pw
});
Expand Down Expand Up @@ -81,6 +84,8 @@ export function excelDecodeRaw(data:Uint8Array, cp?:number, pw?:string):RawWorkB
type: "array",
dense: true,
raw: true,
cellStyles: true,
cellDates: true,
codepage: cp,
password: pw
});
Expand All @@ -107,7 +112,16 @@ export function excelDecode(data:Uint8Array, cp?:number, pw?:string):Record<stri
const columns:string[] = [];

for(const column of <(RawWorkCell | undefined)[]>row ?? []){
columns.push(!column || column.t === "e" ? "" : column.w ?? "");
if(!column || column.t === "e" || column.v === undefined){
columns.push("");
}
else if(column.v instanceof Date){
column.v.setMinutes(new Date().getTimezoneOffset());
columns.push(dtSerial(column.v, true));
}
else{
columns.push(`${column.v}`);
}
}

rows.push(columns);
Expand Down

0 comments on commit a7fd657

Please sign in to comment.