Guidelines fix
This commit is contained in:
@ -1,11 +0,0 @@
|
||||
### Format Colon Timestamp from Date (12 hour format)
|
||||
|
||||
Utilizes to12Hour() to transform date.getHours() to 12 hour format and toDigits to maintain double digits for time integers. Formats integers from given date object into a colon time representation.
|
||||
|
||||
```js
|
||||
let toColonTime12 = ( date ) => {
|
||||
let times = [ to12Hour(date.getHours()), date.getMinutes(), date.getSeconds() ];
|
||||
return times.map( t => setDigits(t, 2, 1) ).join(":");
|
||||
}
|
||||
// toColonTime12(new Date()) -> "08:38:00"
|
||||
```
|
||||
@ -1,16 +0,0 @@
|
||||
### Get Meridiem of Integer (12 hour format)
|
||||
|
||||
Use the modulo operator (`%`) to transform an integer to a 12 hour clock format. Affix appropriate meridiem to stringified integer.
|
||||
|
||||
```js
|
||||
const toMeridiem = int => {
|
||||
int = parseInt(int);
|
||||
const meridiems = ["am", "pm"];
|
||||
let period = int > 11 ? 1 : 2;
|
||||
|
||||
return int === 0 || int === 12 || int === 24 ? 12 + meridiems[period] : int % 12 + meridiems[period];
|
||||
}
|
||||
// toMeridiem(0) -> "12am"
|
||||
// toMeridiem(9) -> "9am"
|
||||
// toMeridiem(13) -> "1pm"
|
||||
```
|
||||
13
snippets/getColonTime.md
Normal file
13
snippets/getColonTime.md
Normal file
@ -0,0 +1,13 @@
|
||||
### toColonTime
|
||||
|
||||
Returns transformed time integers from provided date object to "colon time" representation. Formats hour to 12 hour and maintains digit length of colon time format (HH:MM:SS).
|
||||
|
||||
```js
|
||||
let toColonTime = ( date ) => {
|
||||
let times = [ date.getHours(), date.getMinutes(), date.getSeconds() ];
|
||||
times[0] = times[0] === 0 || times[0] === 12 || times[0] === 24 ? 12 : times[0] % 12;
|
||||
|
||||
return times.map( time => time.toString().padStart(2, "0") ).join(":");
|
||||
}
|
||||
// toColonTime12(new Date()) -> "08:38:00"
|
||||
```
|
||||
15
snippets/getMeridiemOfInteger.md
Normal file
15
snippets/getMeridiemOfInteger.md
Normal file
@ -0,0 +1,15 @@
|
||||
### toMeridiem
|
||||
|
||||
Uses modulo operator (`%`) to transform an integer to a 12 hour clock format. Stringifies transformed integer with concatenated meridiem suffix. Maintains 12 hour format principles with conditional check (0am - 12am).
|
||||
|
||||
```js
|
||||
const toMeridiem = num => {
|
||||
const meridiems = ["am", "pm"];
|
||||
let period = num > 11 ? 1 : 2;
|
||||
|
||||
return num === 0 || num === 12 || num === 24 ? 12 + meridiems[period] : num % 12 + meridiems[period];
|
||||
}
|
||||
// toMeridiem(0) -> "12am"
|
||||
// toMeridiem(9) -> "9am"
|
||||
// toMeridiem(13) -> "1pm"
|
||||
```
|
||||
@ -1,14 +0,0 @@
|
||||
### Maintain Digits
|
||||
|
||||
Use the modulo operator (`%`) to find values of single and tens digits.
|
||||
Find which ordinal pattern digits match.
|
||||
If digit is found in teens pattern, use teens ordinal.
|
||||
|
||||
```js
|
||||
const setDigits = ( int=0, len=1, dir=0 ) => {
|
||||
return dir > 0 ? int.toString().padStart(len, "0") : int.toString().padEnd(len, "0");
|
||||
}
|
||||
// setDigits(1, 2, 0) -> "10"
|
||||
// setDigits(1, 2, 1) -> "01"
|
||||
// setDigits(11, 2, 1) -> "11"
|
||||
```
|
||||
14
snippets/maintainDigits.md
Normal file
14
snippets/maintainDigits.md
Normal file
@ -0,0 +1,14 @@
|
||||
### setDigits
|
||||
|
||||
Uses `String.padStart()` or `String.padEnd()` to maintain digit length of a provided integer. Returns stringified integer.
|
||||
|
||||
Control direction (0 = before integer, 1 = after integer).
|
||||
|
||||
```js
|
||||
const setDigits = ( num=0, len=1, direction=0 ) => {
|
||||
return direction > 0 ? num.toString().padStart(len, "0") : num.toString().padEnd(len, "0");
|
||||
}
|
||||
// setDigits(1, 2, 0) -> "10"
|
||||
// setDigits(1, 2, 1) -> "01"
|
||||
// setDigits(11, 2, 1) -> "11"
|
||||
```
|
||||
13
snippets/to12HourFormat.md
Normal file
13
snippets/to12HourFormat.md
Normal file
@ -0,0 +1,13 @@
|
||||
### to12Hour
|
||||
|
||||
Uses the modulo operator (`%`) to transform an integer to a 12 hour clock format.
|
||||
|
||||
```js
|
||||
const to12Hour = ( num ) => {
|
||||
|
||||
return num === 0 || num === 12 || num === 24 ? 12 : num % 12;
|
||||
}
|
||||
// to12Hour(9) -> "9"
|
||||
// to12Hour(9) -> "9"
|
||||
// to12Hour(13) -> "1"
|
||||
```
|
||||
@ -1,14 +0,0 @@
|
||||
### Transform Int (12 Hour Format)
|
||||
|
||||
Use the modulo operator (`%`) to transform an integer to a 12 hour clock format.
|
||||
|
||||
```js
|
||||
const to12Hour = ( int ) => {
|
||||
int = parseInt(int);
|
||||
|
||||
return int === 0 || int === 12 || int === 24 ? 12 : int % 12;
|
||||
}
|
||||
// to12Hour(9) -> "9"
|
||||
// to12Hour(9) -> "9"
|
||||
// to12Hour(13) -> "1"
|
||||
```
|
||||
Reference in New Issue
Block a user