Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat[ATLAS-104]: Introducing Date & Time Module #54

Closed
wants to merge 31 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
32aa462
add formatDate - DateTime Module
RgnDunes Jan 18, 2024
763e7e0
add formatDateTime - DateTime Module
RgnDunes Jan 18, 2024
a616f42
add formatTime - DateTime Module
RgnDunes Jan 18, 2024
ab60331
add add & subtract - DateTime Module
RgnDunes Jan 18, 2024
0e341d6
add getFirstDayOfWeek, getQuarter, getWeek, getWeekdays - DateTime Mo…
RgnDunes Jan 18, 2024
a8087d5
add isAfter, isBefore, isLeapYear, isSameDay, isValidDate
RgnDunes Jan 18, 2024
e8fd26b
add getRelativeTime - DateTime Module
RgnDunes Jan 18, 2024
868db86
add parseDate, parseDateWithFormat, localeDateFormats - DateTime Module
RgnDunes Jan 18, 2024
87386cf
[fix]: syntax errors
RgnDunes Jan 18, 2024
661f50d
add dateTime module export
RgnDunes Jan 18, 2024
555f445
Create cuddly-eggs-design.md
RgnDunes Jan 18, 2024
31f8f7a
add locale check and state support for locale estimation
RgnDunes Jan 18, 2024
3770970
push build
RgnDunes Jan 18, 2024
2559974
update build
RgnDunes Jan 18, 2024
bbbebf5
remove build
RgnDunes Jan 18, 2024
14cdb79
add support for intlOptions
RgnDunes Jan 18, 2024
8df37a8
[fix]: eslint errors
RgnDunes Jan 18, 2024
499b653
Merge remote-tracking branch 'origin/master' into ATLAS-104-date-modu…
RgnDunes Jan 22, 2024
b819ee5
add parseDateTime
RgnDunes Jan 22, 2024
f2f36d0
add stringToDate desc in utils
RgnDunes Jan 22, 2024
1374936
migrated dateTime module to i18nify-js package
RgnDunes Jan 22, 2024
00ebcc6
refactor parseDateTime module
RgnDunes Jan 23, 2024
34f49b0
minor fixes
RgnDunes Jan 24, 2024
db96b5b
Merge remote-tracking branch 'origin/master' into ATLAS-104-date-modu…
RgnDunes Jan 24, 2024
ce8f59a
remove extra files
RgnDunes Jan 29, 2024
10fd174
[chore]: update date module api contracts
RgnDunes Feb 14, 2024
462add3
Merge remote-tracking branch 'origin/master' into ATLAS-104-date-modu…
RgnDunes Feb 14, 2024
da36410
[fix]: fix invalid parameter in formatDate
RgnDunes Feb 14, 2024
727a19f
[chore]: assign default empty object to intlOptions in parseDateTime
RgnDunes Feb 14, 2024
140f42e
docs[ATLAS-104]: Adding Documentation for Date & Time Module (#56)
RgnDunes Feb 14, 2024
e591663
test[ATLAS-104]: Adding Unit Tests for Date & Time Module (#55)
RgnDunes Feb 14, 2024
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
Prev Previous commit
Next Next commit
add add & subtract - DateTime Module
  • Loading branch information
RgnDunes committed Jan 18, 2024
commit ab603315cdec49bbc7d557217ddca10f4a069720
31 changes: 31 additions & 0 deletions src/modules/dateTime/add.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { withErrorBoundary } from '../../common/errorBoundary';

/**
* Adds a specified amount of time to a date.
*
* @param date The original date.
* @param value The amount to add.
* @param unit The unit of time to add (e.g., 'days', 'months', 'years').
* @returns A new Date object with the time added.
*/
const add = (
date: Date,
value: number,
unit: 'days' | 'months' | 'years',
): Date => {
const result = new Date(date);
switch (unit) {
case 'days':
result.setDate(result.getDate() + value);
break;
case 'months':
result.setMonth(result.getMonth() + value);
break;
case 'years':
result.setFullYear(result.getFullYear() + value);
break;
}
return result;
};

export default withErrorBoundary<typeof add>(add);
20 changes: 20 additions & 0 deletions src/modules/dateTime/subtract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { withErrorBoundary } from '../../common/errorBoundary';
import add from './add';

/**
* Subtracts a specified amount of time from a date.
*
* @param date The original date.
* @param value The amount to subtract.
* @param unit The unit of time to subtract (e.g., 'days', 'months', 'years').
* @returns A new Date object with the time subtracted.
*/
const subtract = (
date: Date,
value: number,
unit: 'days' | 'months' | 'years',
): Date => {
return add(date, -value, unit); // Reuse the add function with negative value
};

export default withErrorBoundary<typeof subtract>(subtract);