Skip to content

Commit

Permalink
Code cleanup. JSDoc improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexagon committed Sep 18, 2022
1 parent bb5b234 commit 9a71cbd
Show file tree
Hide file tree
Showing 14 changed files with 1,447 additions and 72 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ import minitz from "minitz";
JavaScript

```javascript
import minitz from "https://deno.land/x/[email protected].1/src/minitz.js";
import minitz from "https://deno.land/x/[email protected].3/src/minitz.js";

// ...
```

TypeScript

```typescript
import { minitz } from "https://deno.land/x/[email protected].1/src/minitz.js";
import { minitz } from "https://deno.land/x/[email protected].3/src/minitz.js";

// ...
```
Expand Down
35 changes: 20 additions & 15 deletions dist/minitz.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
* @property {string} timezone - Time zone in IANA database format 'Europe/Stockholm'
*/

/*
/**
* Converts a date/time from a specific timezone to a normal date object using the system local time
*
* Shortcut for minitz.fromTZ(minitz.tp(...));
*
* @public
* @constructor
*
* @param {Number} year - 1970--
* @param {Number} month - 1-12
Expand All @@ -59,39 +59,42 @@
* @param {string} timezone - Time zone in IANA database format 'Europe/Stockholm'
* @param {boolean} [throwOnInvalidTime] - Default is to return the adjusted time if the call happens during a Daylight-Saving-Time switch.
* E.g. Value "01:01:01" is returned if input time is 00:01:01 while one hour got actually
* skipped, going from 23:59:59 to 01:00:00. Setting this flag makes the library throw instead.
* skipped, going from 23:59:59 to 01:00:00. Setting this flag makes the library throw an exception instead.
* @returns {date} - Normal date object with correct UTC and system local time
*
*/
*/
function minitz(year, month, day, hour, minute, second, timezone, throwOnInvalidTime) {
return minitz.fromTZ(minitz.tp(year, month, day, hour, minute, second, timezone), throwOnInvalidTime);
}

/**
* Converts a date/time from a specific timezone to a normal date object using the system local time
*
*
* @public
*
* @static
*
* @param {string} localTimeString - ISO8601 formatted local time string, non UTC
* @param {string} timezone - Time zone in IANA database format 'Europe/Stockholm'
* @param {boolean} [throwOnInvalidTime] - Default is to return the adjusted time if the call happens during a Daylight-Saving-Time switch.
* E.g. Value "01:01:01" is returned if input time is 00:01:01 while one hour got actually
* skipped, going from 23:59:59 to 01:00:00. Setting this flag makes the library throw instead.
* @returns {date} - Normal date object
* skipped, going from 23:59:59 to 01:00:00. Setting this flag makes the library throw an exception instead.
* @return {date} - Normal date object
*
*/
minitz.fromTZISO = function(localTimeString, timezone, throwOnInvalidTime) {
minitz.fromTZISO = (localTimeString, timezone, throwOnInvalidTime) => {
return minitz.fromTZ(parseISOLocal(localTimeString, timezone), throwOnInvalidTime);
};

/**
* Converts a date/time from a specific timezone to a normal date object using the system local time
*
* @public
* @static
*
* @param {TimePoint} date - Object with specified timezone
* @param {boolean} [throwOnInvalidTime] - Default is to return the adjusted time if the call happens during a Daylight-Saving-Time switch.
* E.g. Value "01:01:01" is returned if input time is 00:01:01 while one hour got actually
* skipped, going from 23:59:59 to 01:00:00. Setting this flag makes the library throw instead.
* skipped, going from 23:59:59 to 01:00:00. Setting this flag makes the library throw an exception instead.
* @returns {date} - Normal date object
*/
minitz.fromTZ = function(timePoint, throwOnInvalidTime) {
Expand Down Expand Up @@ -150,6 +153,7 @@
* time zone, use vanilla JS. See the example below.
*
* @public
* @static
*
* @param {date} date - Input date
* @param {string} [tzString] - Timezone string in Europe/Stockholm format
Expand Down Expand Up @@ -192,10 +196,11 @@
};
};

/*
/**
* Convenience function which returns a TimePoint object for later use in fromTZ
*
* @public
* @static
*
* @param {Number} year - 1970--
* @param {Number} month - 1-12
Expand All @@ -220,11 +225,11 @@
*
* @returns {number} - Offset in ms between UTC and timeZone
*/
const getTimezoneOffset = (timeZone, date = new Date()) => {
function getTimezoneOffset(timeZone, date = new Date()) {
const tz = date.toLocaleString("en", {timeZone, timeStyle: "long"}).split(" ").slice(-1)[0];
const dateString = date.toString();
return Date.parse(`${dateString} UTC`) - Date.parse(`${dateString} ${tz}`);
};
}


/**
Expand All @@ -237,7 +242,7 @@
* with all components, e.g. 2015-11-24T19:40:00
* @returns {TimePoint} - TimePoint instance from parsing the string
*/
const parseISOLocal = function (dateTimeString, timezone) {
function parseISOLocal(dateTimeString, timezone) {
const dateTimeStringSplit = dateTimeString.split(/\D/);

// Check for completeness
Expand Down Expand Up @@ -277,7 +282,7 @@
return minitz.tp(year, month, day, hour, minute, second, timezone);
}
}
};
}

minitz.minitz = minitz;

Expand Down
2 changes: 1 addition & 1 deletion dist/minitz.min.js

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

2 changes: 1 addition & 1 deletion dist/minitz.min.js.map

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

Loading

0 comments on commit 9a71cbd

Please sign in to comment.