mirror of
https://github.com/filecoin-project/slate.git
synced 2024-11-26 04:19:49 +03:00
feat(utilities): add formatDateToString to format uploaded files date to using today and yesterday
This commit is contained in:
parent
119312afa1
commit
9b632cacc3
@ -4,6 +4,8 @@ import * as Strings from "~/common/strings";
|
||||
import * as Validations from "~/common/validations";
|
||||
import * as Constants from "~/common/constants";
|
||||
|
||||
import moment from "moment";
|
||||
|
||||
//NOTE(martina): this file is for utility functions that do not involve API calls
|
||||
//For API related utility functions, see common/user-behaviors.js
|
||||
//And for uploading related utility functions, see common/file-utilities.js
|
||||
@ -145,3 +147,25 @@ export function mapResponsiveProp(prop, mapper) {
|
||||
}
|
||||
|
||||
export const copyToClipboard = (text) => navigator.clipboard.writeText(text);
|
||||
|
||||
export function formatDateToString(date) {
|
||||
const providedDate = moment(date);
|
||||
const today = moment();
|
||||
const yesterday = moment().subtract(1, "day");
|
||||
|
||||
if (today.isSame(providedDate, "day")) {
|
||||
return "Today at " + providedDate.format("h:mm:ssA");
|
||||
}
|
||||
|
||||
if (yesterday.isSame(providedDate, "day")) {
|
||||
return "Yesterday at " + providedDate.format("h:mm:ssA");
|
||||
}
|
||||
|
||||
return providedDate.format("MMM D, YYYY") + " at " + providedDate.format("h:mm:ssA");
|
||||
}
|
||||
|
||||
export const clamp = (value, min, max) => {
|
||||
if (value < min) return min;
|
||||
if (value > max) return max;
|
||||
return value;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user