month-utils
v0.8.2
Published
Time slot scheduling classes relative to months as storage units
Downloads
4
Maintainers
Readme
Month Utils
This is a short collection of methods for working with months and timestamps.
This is not a formatting library. It helps switch between Date objects and timestamps for such needs as finding the first timestamp of the first day of a month when the some later day is known. It is just a few of these kinds of methods.
Since the small number of methods are common occurring requirements the module proves useful to have for a number of projects.
Since the number of methods is few, the module is very short and uses less than 8K of space uncompressed and 4K compressed by terser.
Install
For use in node.js projects:
npm install i --save month-utils
In your node.js program you can access classes in the following manner:
const month_utils = require('month-utils')
Web Page Use
A rollup.config.js file has been added to the package. The npm package should be released after running npm run build
. (That is best effort.)
Builds that use rollup may simply include event-days in their devDependencies field within package.json. It may help to run a second npm install a such:
npm install i --save-dev month-utils
Example: This class is being used in a Svelte project. The module is included in an App.svelte file as follows:
import month_utils from 'month-utils'
Constants
- TWENTY_FOUR
- ONE_WEEK
- ONE_MONTH
- MIN15
- MIN30
- HOUR
Methods
prev_midnight(local_clock_date)
next_midnight(local_clock_date)
part_of_day(local_clock_date,partial)
hours_of(lapse)
calc_days(t_time)
in_interval(instant,t_start,t_end)
first_day_of_month(a_date)
first_day_of_month_ts(timestamp)
lower_month_bounday(timestamp)
first_day_of_next_month(a_date)
first_day_of_next_month_ts(timestamp)
next_month_start
first_day_of_relative_month(a_date,nth)
first_day_of_relative_month_ts(timestamp,nth)
same_day(t1,t2)
day_is_clock_day(a_day,year,month,local_clock_date)
day_is_before_clock_day(a_day,year,month,local_clock_date)
day_is_after_clock_day(a_day,year,month,local_clock_date)
prev midnight
- Date -> timestamp
Given a date object for a time on a pariticular day, returns the timestamp of the preceding midnight.
next midnight
- Date -> timestamp
Given a date object for a time on a pariticular day, returns the timestamp of the midnight for the end of the day.
part of day
- Date, number -> timestamp
Given a date object for a time on a pariticular day, returns the timestamp equal to the partial mutiplied by the difference between the next midnight and the prev midnight added to the preceding midnight. That is, the timestamp of a fraction of the day.
hours of
- timestamp -> number
Given a timestamp representing a duration, returns the number of hours.
calc days
- timestamp -> number
Given a timestamp representing a duration, returns the number of days.
in interval
- timestamp, timestamp, timestamp -> boolean
Given a timestamp representing an instant of time, a start time and an end time for an interval, returns true if the instant is in the interval.
first day of month
- Date-> timestamp
Given a Date representation of a point in time, returns the timestamp of the midnight starting the first day of the month containing the point in time.
first day of month ts
- timestamp-> timestamp
The same as first day of month but this takes a timestamp representation of the point in time.
lower month bounday
- timestamp-> timestamp
Alias for first day of month ts.
first day of next month
- Date-> timestamp
Given a Date representation of a point in time, returns the timestamp of the midnight starting the first day of the next month not containing the point in time.
first day of next month ts
- timestamp-> timestamp
The same as first day of next month but this takes a timestamp representation of the point in time.
lower month bounday
- timestamp-> timestamp
Alias for first day of next month ts.
first day of relative month
- Date, number -> timestamp
Given a Date representation of a point in time, returns the timestamp of the midnight starting the first day of the nth (number) beyond the month containing the point in time.
first day of relative month ts
- timestamp, number-> timestamp
The same as first day of relative month but this takes a timestamp representation of the point in time.
same day
- timestamp, timestamp-> boolean
Returns true if the two timestamps have the same date.
day is clock day
- number, number, number, Date -> boolean
(day, year month, Date) returns true if the day given is the same day as the Date's day.
day is before clock day
- number, number, number, Date -> boolean
(day, year month, Date) returns true if the day given is less than the day that is the Date's day where the time is taken from the midnight before the day.
day is after clock day
- number, number, number, Date -> boolean
(day, year month, Date) returns true if the day given is greater than the day that is the Date's day where the time is taken from the midnight ending the day.