-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #295 from dhanush-2397/dev
creating a cron expression for oracle
- Loading branch information
Showing
3 changed files
with
25 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,23 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { Injectable } from "@nestjs/common"; | ||
@Injectable() | ||
export class DateService{ | ||
|
||
getCurrentTime24(): string { | ||
const currentDate = new Date(); | ||
const currentHour = currentDate.getHours(); | ||
const currentMinute = currentDate.getMinutes(); | ||
return `${currentHour}:${currentMinute}`; | ||
} | ||
|
||
// Function to check if the current time is greater than 12 PM | ||
isTimeGreaterThan12PM(timeString) { | ||
const [hours, minutes] = timeString.split(':'); | ||
const hour = parseInt(hours, 10); | ||
const minute = parseInt(minutes, 10); | ||
|
||
// Check if it's past 12 PM (noon) | ||
return hour > 12 || (hour === 12 && minute > 0); | ||
} | ||
|
||
getCurrentTimeForCronSchedule(){ | ||
let currentTime = this.getCurrentTime24() | ||
if (this.isTimeGreaterThan12PM(currentTime)) { | ||
// Convert to IST (add 5 hours and 30 minutes for the UTC+5:30 offset) | ||
const [hours, minutes] = currentTime.split(':'); | ||
// const hour = parseInt(hours, 10) + 5; | ||
// const minute = parseInt(minutes, 10) + 30; | ||
export class DateService { | ||
getCurrentISTTime():Date { | ||
const now = new Date(); | ||
const istOffset = 330 * 60 * 1000; | ||
|
||
const currentISTTime = new Date(now.getTime() + istOffset); | ||
|
||
console.log("Hours is:", hours); | ||
console.log("Minutes is:",minutes); | ||
let min = parseInt(minutes) + 2 | ||
return [hours,min] | ||
} else { | ||
return currentTime | ||
return currentISTTime; | ||
} | ||
} | ||
|
||
getCronExpression(currentISTTime: Date):string { | ||
const hours = currentISTTime.getUTCHours(); | ||
const minutes = currentISTTime.getUTCMinutes(); | ||
|
||
|
||
} | ||
const scheduledMinutes = (minutes + 9) % 60; | ||
const scheduledHours = hours + Math.floor((minutes + 9) / 60); | ||
const cronExpression = `0 ${scheduledMinutes} ${scheduledHours} * * ?`; | ||
|
||
return cronExpression; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters