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
10 changes: 0 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"email-validator": "^2.0.4",
"gradle-to-js": "2.0.1",
"jsonwebtoken": "^9.0.2",
"moment": "^2.29.4",
"opener": "^1.5.2",
"parse-duration": "^2.1.6",
"plist": "^3.1.0",
Expand Down
40 changes: 26 additions & 14 deletions script/command-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const childProcess = require("child_process");
import debugCommand from "./commands/debug";
import * as fs from "fs";
import * as chalk from "chalk";
import * as moment from "moment";
import * as os from "os";
import * as path from "path";
import * as semver from "semver";
Expand Down Expand Up @@ -153,7 +152,7 @@ async function accessKeyPatch(command: cli.IAccessKeyPatchCommand): Promise<void
}

if (willUpdateTtl) {
const expirationDate = moment(accessKey.expires).format("LLLL");
const expirationDate = new Date(accessKey.expires).toLocaleString("en-US", { dateStyle: "full", timeStyle: "short" });
if (willUpdateName) {
logMessage += ` and changed its expiration date to ${expirationDate}`;
} else {
Expand Down Expand Up @@ -616,18 +615,6 @@ async function logout(_command: cli.ICommand): Promise<void> {
deleteConnectionInfoCache();
}

function formatDate(unixOffset: number): string {
const date: moment.Moment = moment(unixOffset);
const now: moment.Moment = moment();
if (Math.abs(now.diff(date, "days")) < 30) {
return date.fromNow(); // "2 hours ago"
} else if (now.year() === date.year()) {
return date.format("MMM D"); // "Nov 6"
} else {
return date.format("MMM D, YYYY"); // "Nov 6, 2014"
}
}

function printAppList(format: string, apps: App[]): void {
if (format === "json") {
printJson(apps);
Expand Down Expand Up @@ -952,6 +939,31 @@ async function getAppVersionFromXcodeProject(
return { appVersion: marketingVersion, buildNumber: String(currentProjectVersion) };
}

const relativeTimeFormat = new Intl.RelativeTimeFormat("en-US", { numeric: "auto" });
const RELATIVE_TIME_UNITS: Array<[unit: Intl.RelativeTimeFormatUnit, ms: number]> = [
["day", 24 * 60 * 60 * 1000],
["hour", 60 * 60 * 1000],
["minute", 60 * 1000],
["second", 1000],
];

// "2 hours ago" within 30 days, otherwise "Nov 6" in the current year and "Nov 6, 2014" before it
function formatDate(unixOffset: number): string {
if (!Number.isFinite(unixOffset)) {
return "";
}

const msFromNow: number = unixOffset - Date.now();
if (Math.abs(msFromNow) < 30 * RELATIVE_TIME_UNITS[0][1]) {
const [unit, ms] = RELATIVE_TIME_UNITS.find(([, ms]) => Math.abs(msFromNow) >= ms) ?? ["second", 1000];
return relativeTimeFormat.format(Math.round(msFromNow / ms), unit);
}

const date = new Date(unixOffset);
const year = date.getFullYear() === new Date().getFullYear() ? undefined : "numeric";
return date.toLocaleDateString("en-US", { month: "short", day: "numeric", year });
}

function printJson(object: any): void {
log(JSON.stringify(object, /*replacer=*/ null, /*spacing=*/ 2));
}
Expand Down
3 changes: 1 addition & 2 deletions script/commands/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import * as childProcess from "child_process";
import * as cli from "../../script/types/cli";
import * as moment from "moment";
import * as path from "path";

const simctl = require("simctl");
Expand Down Expand Up @@ -111,7 +110,7 @@ function processLogData(logData: Buffer) {
// log message prefix that is added to each entry.
const message = line.substring(line.indexOf(logMessagePrefix) + logMessagePrefix.length);

const timeStamp = moment().format("hh:mm:ss");
const timeStamp = new Date().toLocaleTimeString("en-US", { hourCycle: "h23" });
return `[${timeStamp}] ${message}`;
})
.forEach((line: string) => console.log(line));
Expand Down
4 changes: 2 additions & 2 deletions test/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ describe("CLI", () => {
await execute(command);

assertLoggedOnce(
'Successfully changed the expiration date of the "Test name" access key to Wednesday, August 17, 2016 12:07 PM.'
'Successfully changed the expiration date of the "Test name" access key to Wednesday, August 17, 2016 at 12:07 PM.'
);
});

Expand All @@ -171,7 +171,7 @@ describe("CLI", () => {
await execute(command);

assertLoggedOnce(
'Successfully renamed the access key "Test name" to "Updated name" and changed its expiration date to Wednesday, August 17, 2016 12:07 PM.'
'Successfully renamed the access key "Test name" to "Updated name" and changed its expiration date to Wednesday, August 17, 2016 at 12:07 PM.'
);
});

Expand Down
Loading