1. /**
    
  2.  * Copyright (c) Meta Platforms, Inc. and affiliates.
    
  3.  *
    
  4.  * This source code is licensed under the MIT license found in the
    
  5.  * LICENSE file in the root directory of this source tree.
    
  6.  *
    
  7.  * @flow
    
  8.  */
    
  9. 
    
  10. import type {SchedulingEvent} from '../types';
    
  11. 
    
  12. import prettyMilliseconds from 'pretty-ms';
    
  13. 
    
  14. export function formatTimestamp(ms: number): string {
    
  15.   return (
    
  16.     ms.toLocaleString(undefined, {
    
  17.       minimumFractionDigits: 1,
    
  18.       maximumFractionDigits: 1,
    
  19.     }) + 'ms'
    
  20.   );
    
  21. }
    
  22. 
    
  23. export function formatDuration(ms: number): string {
    
  24.   return prettyMilliseconds(ms, {millisecondsDecimalDigits: 1});
    
  25. }
    
  26. 
    
  27. export function trimString(string: string, length: number): string {
    
  28.   if (string.length > length) {
    
  29.     return `${string.slice(0, length - 1)}`;
    
  30.   }
    
  31.   return string;
    
  32. }
    
  33. 
    
  34. export function getSchedulingEventLabel(event: SchedulingEvent): string | null {
    
  35.   switch (event.type) {
    
  36.     case 'schedule-render':
    
  37.       return 'render scheduled';
    
  38.     case 'schedule-state-update':
    
  39.       return 'state update scheduled';
    
  40.     case 'schedule-force-update':
    
  41.       return 'force update scheduled';
    
  42.     default:
    
  43.       return null;
    
  44.   }
    
  45. }