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

[cascading] from release/11.1 to release/11.2 #2831

Merged
merged 2 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/code-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
with:
install-jdk: 'true'
- name: Cache Jest
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
env:
hash: ${{ hashFiles('package.json', 'tsconfig.base.json', 'tsconfig.build.json', 'nx.json') }}
with:
Expand Down Expand Up @@ -91,7 +91,7 @@ jobs:
- name: Setup
uses: ./tools/github-actions/setup
- name: Cache Eslint
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: .cache/eslint
key: ${{ runner.os }}-eslint-${{ hashFiles('yarn.lock') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/it-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
run: echo "currentMonth=$(date +'%Y-%m')" >> $GITHUB_ENV
shell: bash
- name: Cache test-app yarn
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: |
.cache/test-app
Expand Down
27 changes: 26 additions & 1 deletion packages/@ama-sdk/core/src/fwk/date.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ describe('DateTime', () => {
expect(dateUtils).toEqual(dateCompare);
});

it('should support daylight saving time switch', () => {
expect((new Date('1972-05-28T00:00:00')).getTimezoneOffset()).toBe(-120);
expect((new Date('1972-05-27T23:59:59')).getTimezoneOffset()).toBe(-60);
const dateUtils = new utils.DateTime('1972-05-28T00:00:00');
// At midnight in italy, for this date, time should be 1 am
expect(dateUtils.toJSON()).toEqual('1972-05-28T01:00:00.000');
});

it('should ignore timezone of datetime', () => {
const date1 = '2015-03-25T12:00:00-02:00';
const date2 = '2015-03-25T12:00:00+05:00';
Expand Down Expand Up @@ -104,8 +112,25 @@ describe('Date', () => {
it('should be converted to a Js DateTime', () => {
const date1 = '1988-06-07';

const dateCompare = (new utils.DateTime('1988-06-07T12:00:00Z'));
const dateCompare = (new utils.DateTime('1988-06-07T00:00:00Z'));

expect((new utils.Date(date1))).toEqual(dateCompare);
});

it('should be at midnight for any date but daylight switch at midnight', () => {
const date1 = new utils.Date('1988-06-07');

expect(date1.getHours()).toEqual(0);
expect(date1.getMinutes()).toEqual(0);
expect(date1.getSeconds()).toEqual(0);
});

it('should support daylight saving time switch', () => {
expect((new Date('1972-05-28T00:00:00')).getTimezoneOffset()).toBe(-120);
expect((new Date('1972-05-27T23:59:59')).getTimezoneOffset()).toBe(-60);
const dateUtils = new utils.Date('1972-05-28');
// The day should be correct and not 27
expect(dateUtils.toJSON()).toEqual('1972-05-28');
expect(dateUtils.getDate()).toBe(28);
});
});
20 changes: 13 additions & 7 deletions packages/@ama-sdk/core/src/fwk/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ export function pad(val: number, digits: number = 2): string {
return '0'.repeat(Math.max(0, digits - str.length)) + str;
}

export class CommonDate extends Date {
function getNewTimeZoneWithOffset(dateArgs: any[], timezoneOffset: number) {
const newDateArgs = [...dateArgs];
newDateArgs[0] += `${timezoneOffset < 0 ? '+' : '-'}${pad(Math.floor(Math.abs(timezoneOffset / 60)))}:${pad(Math.abs(timezoneOffset % 60))}`;
return newDateArgs;
}

export class CommonDate extends Date {
/**
* Removes timezone information from ISO8601 strings (Received from DAPI)
*/
Expand All @@ -34,10 +39,13 @@ export class CommonDate extends Date {
args[0] = args[0].substring(0, idx);
}

const TIME_ZONE_OFFSET = ((new (Date as any)(...args)) as Date).getTimezoneOffset();
const ORIGINAL_TIME_ZONE_OFFSET = ((new (Date as any)(...args)) as Date).getTimezoneOffset();

if (idxT > 0) {
args[0] += `${TIME_ZONE_OFFSET < 0 ? '+' : '-'}${pad(Math.floor(Math.abs(TIME_ZONE_OFFSET / 60)))}:${pad(Math.abs(TIME_ZONE_OFFSET % 60))}`;
const newDateArgs = getNewTimeZoneWithOffset(args, ORIGINAL_TIME_ZONE_OFFSET);
// Adjust timezone in case of a daylight saving change mid-offset
const NEW_DATE_TIME_ZONE_OFFSET = ((new (Date as any)(...newDateArgs)) as Date).getTimezoneOffset();
args = getNewTimeZoneWithOffset(args, NEW_DATE_TIME_ZONE_OFFSET);
}
} else if (args[0] instanceof CommonDate) {
args[0] = args[0];
Expand Down Expand Up @@ -75,11 +83,9 @@ export namespace utils {
constructor(year: number, month: number, date?: number)
constructor(...args: any[]) {
if (args && typeof args[0] === 'string' && args[0].lastIndexOf('T') < 0) {
// Set time to 12 to limit scenarios where the native date api is not able to correctly
// compute the offset (for example, italian daylight saving switch prior to 1980).
args[0] = `${args[0]}T12:00:00Z`;
args[0] = `${args[0]}T00:00:00Z`;
} else if (args[0] instanceof _NativeDateClass) {
args[0] = `${args[0].getFullYear()}-${pad(args[0].getMonth() + 1)}-${pad(args[0].getDate())}T12:00:00Z`;
args[0] = `${args[0].getFullYear()}-${pad(args[0].getMonth() + 1)}-${pad(args[0].getDate())}T00:00:00Z`;
}

super(...args);
Expand Down
5 changes: 5 additions & 0 deletions packages/@ama-sdk/core/testing/global-timezone-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Used to test edge case around daylight saving changes
const process = require('node:process');
module.exports = async () => {
process.env.TZ = 'Europe/Rome';
}
1 change: 1 addition & 0 deletions packages/@ama-sdk/core/testing/jest.config.ut.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
// TODO re-enable fake dates when issue fixed https://github.com/sinonjs/fake-timers/issues/437
doNotFake: ['Date']
},
globalSetup: '<rootDir>/testing/global-timezone-setup.js',
testPathIgnorePatterns: [
'<rootDir>/.*/templates/.*',
'<rootDir>/builders/.*',
Expand Down
2 changes: 1 addition & 1 deletion tools/github-actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ runs:
shell: bash
run: corepack enable
- name: Cache dependencies
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: |
~/.cache/ms-playwright
Expand Down
Loading