Skip to content
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
2 changes: 1 addition & 1 deletion src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
BBOX_INIT,
F32_BBOX_INIT,
FeatureTest,
getModificationDate,
info,
isArrayEqual,
LINE_DESCENT_FACTOR,
Expand All @@ -43,6 +42,7 @@ import {
collectActions,
escapeString,
getInheritableProperty,
getModificationDate,
getParentToUpdate,
getRotationMatrix,
IDENTITY_MATRIX,
Expand Down
17 changes: 17 additions & 0 deletions src/core/core_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,22 @@ function stringToUTF16String(str, bigEndian = false) {
return buf.join("");
}

function getModificationDate(date = new Date()) {
if (!(date instanceof Date)) {
date = new Date(date);
}
const buffer = [
date.getUTCFullYear().toString(),
(date.getUTCMonth() + 1).toString().padStart(2, "0"),
date.getUTCDate().toString().padStart(2, "0"),
date.getUTCHours().toString().padStart(2, "0"),
date.getUTCMinutes().toString().padStart(2, "0"),
date.getUTCSeconds().toString().padStart(2, "0"),
];

return buffer.join("");
}

function getRotationMatrix(rotation, width, height) {
switch (rotation) {
case 90:
Expand Down Expand Up @@ -753,6 +769,7 @@ export {
fetchBinaryData,
getInheritableProperty,
getLookupTableFactory,
getModificationDate,
getNewAnnotationsMap,
getParentToUpdate,
getRotationMatrix,
Expand Down
7 changes: 2 additions & 5 deletions src/core/editor/pdf_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,14 @@
import {
deepCompare,
getInheritableProperty,
getModificationDate,
getNewAnnotationsMap,
stringToAsciiOrUTF16BE,
} from "../core_utils.js";
import { Dict, isName, Name, Ref, RefSet, RefSetCache } from "../primitives.js";
import {
getModificationDate,
stringToBytes,
stringToPDFString,
} from "../../shared/util.js";
import { incrementalUpdate, writeValue } from "../writer.js";
import { NameTree, NumberTree } from "../name_number_tree.js";
import { stringToBytes, stringToPDFString } from "../../shared/util.js";
import { AnnotationFactory } from "../annotation.js";
import { BaseStream } from "../base_stream.js";
import { StringStream } from "../stream.js";
Expand Down
20 changes: 1 addition & 19 deletions src/shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const AnnotationMode = {
ENABLE_STORAGE: 3,
};

const AnnotationPrefix = "pdfjs_internal_id_";
const AnnotationEditorPrefix = "pdfjs_internal_editor_";

const AnnotationEditorType = {
Expand Down Expand Up @@ -1122,22 +1123,6 @@ function isArrayEqual(arr1, arr2) {
return true;
}

function getModificationDate(date = new Date()) {
if (!(date instanceof Date)) {
date = new Date(date);
}
const buffer = [
date.getUTCFullYear().toString(),
(date.getUTCMonth() + 1).toString().padStart(2, "0"),
date.getUTCDate().toString().padStart(2, "0"),
date.getUTCHours().toString().padStart(2, "0"),
date.getUTCMinutes().toString().padStart(2, "0"),
date.getUTCSeconds().toString().padStart(2, "0"),
];

return buffer.join("");
}

let NormalizeRegex = null;
let NormalizationMap = null;
function normalizeUnicode(str) {
Expand Down Expand Up @@ -1169,8 +1154,6 @@ function getUuid() {
return bytesToString(buf);
}

const AnnotationPrefix = "pdfjs_internal_id_";

function _isValidExplicitDest(validRef, validName, dest) {
if (!Array.isArray(dest) || dest.length < 2) {
return false;
Expand Down Expand Up @@ -1273,7 +1256,6 @@ export {
FeatureTest,
FONT_IDENTITY_MATRIX,
FormatError,
getModificationDate,
getUuid,
getVerbosityLevel,
ImageKind,
Expand Down
9 changes: 9 additions & 0 deletions test/unit/core_utils_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
escapePDFName,
escapeString,
getInheritableProperty,
getModificationDate,
getSizeInBytes,
isAscii,
isWhiteSpace,
Expand Down Expand Up @@ -557,6 +558,14 @@ describe("core_utils", function () {
});
});

describe("getModificationDate", function () {
it("should get a correctly formatted date", function () {
const date = new Date(Date.UTC(3141, 5, 9, 2, 6, 53));
expect(getModificationDate(date)).toEqual("31410609020653");
expect(getModificationDate(date.toString())).toEqual("31410609020653");
});
});

describe("getSizeInBytes", function () {
it("should get the size in bytes to use to represent a positive integer", function () {
expect(getSizeInBytes(0)).toEqual(0);
Expand Down
9 changes: 0 additions & 9 deletions test/unit/util_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
BaseException,
bytesToString,
createValidAbsoluteUrl,
getModificationDate,
getUuid,
stringToBytes,
stringToPDFString,
Expand Down Expand Up @@ -210,14 +209,6 @@ describe("util", function () {
});
});

describe("getModificationDate", function () {
it("should get a correctly formatted date", function () {
const date = new Date(Date.UTC(3141, 5, 9, 2, 6, 53));
expect(getModificationDate(date)).toEqual("31410609020653");
expect(getModificationDate(date.toString())).toEqual("31410609020653");
});
});

describe("getUuid", function () {
it("should get uuid string", function () {
const uuid = getUuid();
Expand Down
Loading