Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance date formatting and improve test coverage #2379

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/api/IBMiContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -993,8 +993,8 @@ export default class IBMiContent {
"Attribute": object.attribute,
"Text": object.text,
"Size": object.size,
"Created": object.created?.toISOString().slice(0, 19).replace(`T`, ` `),
"Changed": object.changed?.toISOString().slice(0, 19).replace(`T`, ` `),
"Created": safeIsoValue(object.created),
"Changed": safeIsoValue(object.changed),
"Created by": object.created_by,
"Owner": object.owner,
"IASP": object.asp
Expand All @@ -1019,8 +1019,8 @@ export default class IBMiContent {
const tooltip = new MarkdownString(Tools.generateTooltipHtmlTable(path, {
"Text": member.text,
"Lines": member.lines,
"Created": member.created?.toISOString().slice(0, 19).replace(`T`, ` `),
"Changed": member.changed?.toISOString().slice(0, 19).replace(`T`, ` `)
"Created": safeIsoValue(member.created),
"Changed": safeIsoValue(member.changed)
}));
tooltip.supportHtml = true;
return tooltip;
Expand All @@ -1029,7 +1029,7 @@ export default class IBMiContent {
ifsFileToToolTip(path: string, ifsFile: IFSFile) {
const tooltip = new MarkdownString(Tools.generateTooltipHtmlTable(path, {
"Size": ifsFile.size,
"Modified": ifsFile.modified ? new Date(ifsFile.modified.getTime() - ifsFile.modified.getTimezoneOffset() * 60 * 1000).toISOString().slice(0, 19).replace(`T`, ` `) : ``,
"Modified": ifsFile.modified ? safeIsoValue(new Date(ifsFile.modified.getTime() - ifsFile.modified.getTimezoneOffset() * 60 * 1000)) : ``,
"Owner": ifsFile.owner ? ifsFile.owner.toUpperCase() : ``
}));
tooltip.supportHtml = true;
Expand All @@ -1048,4 +1048,12 @@ export default class IBMiContent {
throw new Error(result.stderr);
}
}
}

function safeIsoValue(date: Date|undefined) {
try {
return date ? date.toISOString().slice(0, 19).replace(`T`, ` `) : ``;
} catch (e) {
return `Unknown`;
}
}
4 changes: 2 additions & 2 deletions src/testing/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export const EncodingSuite: TestSuite = {

commands.push(`CRTSRCPF FILE(${library}/${sourceFile}) RCDLEN(112) CCSID(${ccsid})`);
for (const member of members) {
commands.push(`ADDPFM FILE(${library}/${sourceFile}) MBR(${member}) SRCTYPE(TXT)`);
commands.push(`ADDPFM FILE(${library}/${sourceFile}) MBR(${member}) SRCTYPE(TXT) TEXT('Test ${member}')`);
}

commands.push(`CRTDTAARA DTAARA(${library}/${dataArea}) TYPE(*CHAR) LEN(50) VALUE('hi')`);
Expand Down Expand Up @@ -289,7 +289,7 @@ export const EncodingSuite: TestSuite = {

const expectedMembers = await content.getMemberList({ library, sourceFile });
assert.ok(expectedMembers);
assert.ok(expectedMembers.every(member => members.find(m => m === member.name)));
assert.ok(expectedMembers.every(member => members.find(m => m === member.name && member.text?.includes(m))));

const sourceFilter = await content.getObjectList({ library, types: ["*SRCPF"], object: `${connection.variantChars.local[0]}*` });
assert.strictEqual(sourceFilter.length, 1);
Expand Down
Loading