diff --git a/src/core/annotation.js b/src/core/annotation.js index 4962e791a652c..b1b922af65625 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -26,7 +26,6 @@ import { BBOX_INIT, F32_BBOX_INIT, FeatureTest, - getModificationDate, info, isArrayEqual, LINE_DESCENT_FACTOR, @@ -43,6 +42,7 @@ import { collectActions, escapeString, getInheritableProperty, + getModificationDate, getParentToUpdate, getRotationMatrix, IDENTITY_MATRIX, diff --git a/src/core/core_utils.js b/src/core/core_utils.js index 56fa0236f7a39..124dd625cd876 100644 --- a/src/core/core_utils.js +++ b/src/core/core_utils.js @@ -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: @@ -753,6 +769,7 @@ export { fetchBinaryData, getInheritableProperty, getLookupTableFactory, + getModificationDate, getNewAnnotationsMap, getParentToUpdate, getRotationMatrix, diff --git a/src/core/editor/pdf_editor.js b/src/core/editor/pdf_editor.js index d839f3cc64986..4e3b3b0349a8b 100644 --- a/src/core/editor/pdf_editor.js +++ b/src/core/editor/pdf_editor.js @@ -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"; diff --git a/src/shared/util.js b/src/shared/util.js index 089a74349fd37..c42103db197cd 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -69,6 +69,7 @@ const AnnotationMode = { ENABLE_STORAGE: 3, }; +const AnnotationPrefix = "pdfjs_internal_id_"; const AnnotationEditorPrefix = "pdfjs_internal_editor_"; const AnnotationEditorType = { @@ -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) { @@ -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; @@ -1273,7 +1256,6 @@ export { FeatureTest, FONT_IDENTITY_MATRIX, FormatError, - getModificationDate, getUuid, getVerbosityLevel, ImageKind, diff --git a/test/unit/core_utils_spec.js b/test/unit/core_utils_spec.js index 788e70eab5eda..54f5c5e17be50 100644 --- a/test/unit/core_utils_spec.js +++ b/test/unit/core_utils_spec.js @@ -20,6 +20,7 @@ import { escapePDFName, escapeString, getInheritableProperty, + getModificationDate, getSizeInBytes, isAscii, isWhiteSpace, @@ -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); diff --git a/test/unit/util_spec.js b/test/unit/util_spec.js index 447687a3ff28b..a06ffb5c68797 100644 --- a/test/unit/util_spec.js +++ b/test/unit/util_spec.js @@ -17,7 +17,6 @@ import { BaseException, bytesToString, createValidAbsoluteUrl, - getModificationDate, getUuid, stringToBytes, stringToPDFString, @@ -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();