Skip to content

Commit 6bbcb46

Browse files
Merge pull request #21258 from Snuffleupagus/mv-getModificationDate
Move the `getModificationDate` helper function into `src/core/core_utils.js`
2 parents 702d60a + aecb571 commit 6bbcb46

6 files changed

Lines changed: 30 additions & 34 deletions

File tree

src/core/annotation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
BBOX_INIT,
2727
F32_BBOX_INIT,
2828
FeatureTest,
29-
getModificationDate,
3029
info,
3130
isArrayEqual,
3231
LINE_DESCENT_FACTOR,
@@ -43,6 +42,7 @@ import {
4342
collectActions,
4443
escapeString,
4544
getInheritableProperty,
45+
getModificationDate,
4646
getParentToUpdate,
4747
getRotationMatrix,
4848
IDENTITY_MATRIX,

src/core/core_utils.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,22 @@ function stringToUTF16String(str, bigEndian = false) {
716716
return buf.join("");
717717
}
718718

719+
function getModificationDate(date = new Date()) {
720+
if (!(date instanceof Date)) {
721+
date = new Date(date);
722+
}
723+
const buffer = [
724+
date.getUTCFullYear().toString(),
725+
(date.getUTCMonth() + 1).toString().padStart(2, "0"),
726+
date.getUTCDate().toString().padStart(2, "0"),
727+
date.getUTCHours().toString().padStart(2, "0"),
728+
date.getUTCMinutes().toString().padStart(2, "0"),
729+
date.getUTCSeconds().toString().padStart(2, "0"),
730+
];
731+
732+
return buffer.join("");
733+
}
734+
719735
function getRotationMatrix(rotation, width, height) {
720736
switch (rotation) {
721737
case 90:
@@ -753,6 +769,7 @@ export {
753769
fetchBinaryData,
754770
getInheritableProperty,
755771
getLookupTableFactory,
772+
getModificationDate,
756773
getNewAnnotationsMap,
757774
getParentToUpdate,
758775
getRotationMatrix,

src/core/editor/pdf_editor.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,14 @@
2323
import {
2424
deepCompare,
2525
getInheritableProperty,
26+
getModificationDate,
2627
getNewAnnotationsMap,
2728
stringToAsciiOrUTF16BE,
2829
} from "../core_utils.js";
2930
import { Dict, isName, Name, Ref, RefSet, RefSetCache } from "../primitives.js";
30-
import {
31-
getModificationDate,
32-
stringToBytes,
33-
stringToPDFString,
34-
} from "../../shared/util.js";
3531
import { incrementalUpdate, writeValue } from "../writer.js";
3632
import { NameTree, NumberTree } from "../name_number_tree.js";
33+
import { stringToBytes, stringToPDFString } from "../../shared/util.js";
3734
import { AnnotationFactory } from "../annotation.js";
3835
import { BaseStream } from "../base_stream.js";
3936
import { StringStream } from "../stream.js";

src/shared/util.js

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const AnnotationMode = {
6969
ENABLE_STORAGE: 3,
7070
};
7171

72+
const AnnotationPrefix = "pdfjs_internal_id_";
7273
const AnnotationEditorPrefix = "pdfjs_internal_editor_";
7374

7475
const AnnotationEditorType = {
@@ -1122,22 +1123,6 @@ function isArrayEqual(arr1, arr2) {
11221123
return true;
11231124
}
11241125

1125-
function getModificationDate(date = new Date()) {
1126-
if (!(date instanceof Date)) {
1127-
date = new Date(date);
1128-
}
1129-
const buffer = [
1130-
date.getUTCFullYear().toString(),
1131-
(date.getUTCMonth() + 1).toString().padStart(2, "0"),
1132-
date.getUTCDate().toString().padStart(2, "0"),
1133-
date.getUTCHours().toString().padStart(2, "0"),
1134-
date.getUTCMinutes().toString().padStart(2, "0"),
1135-
date.getUTCSeconds().toString().padStart(2, "0"),
1136-
];
1137-
1138-
return buffer.join("");
1139-
}
1140-
11411126
let NormalizeRegex = null;
11421127
let NormalizationMap = null;
11431128
function normalizeUnicode(str) {
@@ -1169,8 +1154,6 @@ function getUuid() {
11691154
return bytesToString(buf);
11701155
}
11711156

1172-
const AnnotationPrefix = "pdfjs_internal_id_";
1173-
11741157
function _isValidExplicitDest(validRef, validName, dest) {
11751158
if (!Array.isArray(dest) || dest.length < 2) {
11761159
return false;
@@ -1273,7 +1256,6 @@ export {
12731256
FeatureTest,
12741257
FONT_IDENTITY_MATRIX,
12751258
FormatError,
1276-
getModificationDate,
12771259
getUuid,
12781260
getVerbosityLevel,
12791261
ImageKind,

test/unit/core_utils_spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
escapePDFName,
2121
escapeString,
2222
getInheritableProperty,
23+
getModificationDate,
2324
getSizeInBytes,
2425
isAscii,
2526
isWhiteSpace,
@@ -557,6 +558,14 @@ describe("core_utils", function () {
557558
});
558559
});
559560

561+
describe("getModificationDate", function () {
562+
it("should get a correctly formatted date", function () {
563+
const date = new Date(Date.UTC(3141, 5, 9, 2, 6, 53));
564+
expect(getModificationDate(date)).toEqual("31410609020653");
565+
expect(getModificationDate(date.toString())).toEqual("31410609020653");
566+
});
567+
});
568+
560569
describe("getSizeInBytes", function () {
561570
it("should get the size in bytes to use to represent a positive integer", function () {
562571
expect(getSizeInBytes(0)).toEqual(0);

test/unit/util_spec.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
BaseException,
1818
bytesToString,
1919
createValidAbsoluteUrl,
20-
getModificationDate,
2120
getUuid,
2221
stringToBytes,
2322
stringToPDFString,
@@ -210,14 +209,6 @@ describe("util", function () {
210209
});
211210
});
212211

213-
describe("getModificationDate", function () {
214-
it("should get a correctly formatted date", function () {
215-
const date = new Date(Date.UTC(3141, 5, 9, 2, 6, 53));
216-
expect(getModificationDate(date)).toEqual("31410609020653");
217-
expect(getModificationDate(date.toString())).toEqual("31410609020653");
218-
});
219-
});
220-
221212
describe("getUuid", function () {
222213
it("should get uuid string", function () {
223214
const uuid = getUuid();

0 commit comments

Comments
 (0)