How replace hours and minutes put by user into current date and compare it - date

I have two Strings with two digits in each (12) and (30) as example(It`s for alarm)
I want to put String in current data, and change current hours and minutes to which user put.
Convert it to programm format(look like 211232131134) for comparison current time with putable.
(4. Do some actions when it will be comparison)
That`s i need get minutes and hours from new date(putting by user), add current year, mm, and d to it. Compare with current date.

What are you writing the code in? In general you could convert the date entered into UNIX time (seconds since 1970-01-01) and get the current time in UNIX time and just compare those as a integer.

Related

How to add TIMEZONE to VS Code User Defined Snippets?

I see the time/date variables available to VS Code User Defined Snippets are:
CURRENT_YEAR The current year
CURRENT_YEAR_SHORT The current year's last two digits
CURRENT_MONTH The month as two digits (example '02')
CURRENT_MONTH_NAME The full name of the month (example 'July')
CURRENT_MONTH_NAME_SHORT The short name of the month (example 'Jul')
CURRENT_DATE The day of the month as two digits (example '08')
CURRENT_DAY_NAME The name of day (example 'Monday')
CURRENT_DAY_NAME_SHORT The short name of the day (example 'Mon')
CURRENT_HOUR The current hour in 24-hour clock format
CURRENT_MINUTE The current minute as two digits
CURRENT_SECOND The current second as two digits
CURRENT_SECONDS_UNIX The number of seconds since the Unix epoch
Unfortunately, without TIMEZONE or TIMEZONE OFFSET from UTC, you can't automatically create an accurate, time-aware timestamp using these variables.
Example:
${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}T${CURRENT_HOUR}:${CURRENT_MINUTE}:${CURRENT_SECOND}
Evaluates to: 2022-06-03T07:32:09, but thats not accurate enough. Without a TIMEZONE identifier, that "timestamp" is +/- 23:59:59 reflection of "actual time".
I need:
2022-06-03T07:32:09-07:00 and I want the timezone offset to adjust for daylight savings time to 2022-11-04T07:32:09-08:00 as appropriate.
Must be human readable. Not going to use Unix time.
How can I do this without spinning up a whole Extension?
I came here looking for the same thing. Its not a snippet, but I use the Insert Date String extension to handle this. You can define the default format as iso, and it comes with a key binding of ctrl-shift-alt-I. Works well enough, but I too would prefer a snippet.

How can I make a database structure in mongodb for saving the date range?

Here I'm saving the date range using golang. Suppose we have to save the all monday comes between the range of the 1-may-2018 to 14-july-2018.
How we will find all the monday between these range using golang and on the other hand we have set the start_time (8:00 A.M.) and the end_time (6:00 P.M.) of the first two coming monday in the database but on the third monday we have a change in the schedule that there is a time change like start_time (9:00 A.M.) and end_time (5:00 P.M.). Then how I will make my database to make this situation in practically using the golang.
Can Anybody help me for this to solve this solution. I made a database for and I do ppr work on it and make some fields shown below:-
Fields for Schedule //Schedule is a collection name
Id (int)
Day (string)
Start_hours (int)
Start_minutes (int)
End_hours (int)
End_minutes (int)
Start_date (timestamp)
End_date (timestamp)
How I will select monday between the selected range and how will I do the situation I explained above can anybody give guidance to me to make this situation easier. Thank you if this is a basic question then I'm really sorry.
I'd make something like this.
Find the first Monday date from the date range (see for example How do I get the first Monday of a given month in Go?
Mondays happen every week, so you can easily find the rest of dates by adding 7 days till the end date
Store all the Monday dates you found with the start and end times
I wouldn't bother with hours and minutes as you can easily get them from the timestamps in Go. Here is the simplified DB structure I would make
Fields for Schedule //Schedule is a collection name
Id (int)
Day (string)
Date (timestamp) // the actual date
Start (timestamp)
End (timestamp)
You don't need any more fields. You can get the day of the week (Day (string) in your structure, e.g. Monday) from the Date field too, but I believe if you want to query the collection by different days, this might speed things up, but be careful if you need to adjust for time zones. If you work with more than one, then store everything in UTC and you may have an extra filed Timezone, cos a date could be Monday for one zone and Sunday for another.
So, the Schedule will hold weekdays and start and end times for each of them. I'm not sure if you need to store initial date ranges, the Schedule collection will hold that range as well, form the first record to the last one. In my mind, I'd initially populate the collection with a given date range, then later on, I can modify it by adding new days, or deleting them.
When you query this collection with some start and end date range for the Date field, if your first result comes newer than 7 days from the start, this means you miss 1 or more entries from the start. If the last result comes older than 7 days from the range end, this means you miss some entries prior to the range end.
There is nothing specific to Go, in my opinion, Go works well with dates and you don't need any special date structures in your DB.

Convert date to Unix time without os.time()

I am developing a plugin written in Lua, and I need a way to calculate Unix time or at least a way to compare 2 date strings.
The function I can use only returns date string in the following format
"1/17/2014 6:50 PM"
Is there a way to convert this string to a Unix time?
Unfortunately I don't have access to the OS library so things like os.time() do not work.
Is there any library or something similar that I can work with?
I also thought about splitting the string into parts, but I need a way to add/subtract time
Just compare normalized timestamps:
function normalize(a)
local m,d,y,h,mi,n=a:match("(%d+)/(%d+)/(%d+)%s+(%d+):(%d+)%s+(%w+)")
if n=="PM" then h=h+12 end
return string.format("%04d%02d%02d%02d%02d",y,m,d,h,mi)
end
Date arithmetic is another story. For a complete, pure Lua date library, see luatz or https://github.com/Tieske/date.
If you need to only compare two time, you don't need to get each time's Unix timestamp. One possible solution is to get the time fields from the string like this:
local time = "1/17/2014 6:50 PM"
local month, day, year, hour, minute, am_pm = time:match("(%d+)/(%d+)/(%d+)%s+(%d+):(%d+)%s+(%w+)")
print(month, day, year, hour, minute, am_pm)
Output: 1 17 2014 6 50 PM
Then compare two time from comparing their year, if they are equal, then month, and so on. Remember to use tonumber to compare them by number, not the string itself.

How to i get the difference of time in hours for a file created time and the current time using perl

How to i get the difference between a file created time and the current time in hours
stat($file)->mtime gives you the last modification time in seconds. Subtract that from time and divide it by 3600 ... that should do the trick.
For calculations involving time or dates you can always rely on DateTime!
For your specific cuestion, you can use the constructor from_epoch to convert from Unix timestamp to DateTime.

Readable date from unix time stamp?

Starting out with an int variable unix time stamp (something like 1290341015), is there a way to get this into a nice human readable date string? The iPhone Mail app has the ideal display of date, where it shows the time or date in the context of the current time.
06:47 (a time today)
Yesterday (received yesterday)
Friday (received last Friday)
09/11/2010 (received more than a week ago)
Is there a way to approximate this?
Calculate relative time in C#
Fuzzy date algorithm
iPhone: Convert date string to a relative time stamp
This has been asked quite a few times before. The final link is the iphone specific one, the others a bit more general.