Skip to content

Commit

Permalink
Merge pull request #2379 from codefori/fix/support_bad_dates
Browse files Browse the repository at this point in the history
Enhance date formatting and improve test coverage
  • Loading branch information
worksofliam authored Nov 27, 2024
2 parents 6b0d425 + c9b9692 commit f4c59e7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
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

0 comments on commit f4c59e7

Please sign in to comment.