aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/time.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/time.c')
-rw-r--r--kernel/time.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/kernel/time.c b/kernel/time.c
index b94bfa8c03e0..fa569885e22b 100644
--- a/kernel/time.c
+++ b/kernel/time.c
@@ -583,6 +583,67 @@ void getnstimestamp(struct timespec *ts)
583} 583}
584EXPORT_SYMBOL_GPL(getnstimestamp); 584EXPORT_SYMBOL_GPL(getnstimestamp);
585 585
586/* Converts Gregorian date to seconds since 1970-01-01 00:00:00.
587 * Assumes input in normal date format, i.e. 1980-12-31 23:59:59
588 * => year=1980, mon=12, day=31, hour=23, min=59, sec=59.
589 *
590 * [For the Julian calendar (which was used in Russia before 1917,
591 * Britain & colonies before 1752, anywhere else before 1582,
592 * and is still in use by some communities) leave out the
593 * -year/100+year/400 terms, and add 10.]
594 *
595 * This algorithm was first published by Gauss (I think).
596 *
597 * WARNING: this function will overflow on 2106-02-07 06:28:16 on
598 * machines were long is 32-bit! (However, as time_t is signed, we
599 * will already get problems at other places on 2038-01-19 03:14:08)
600 */
601unsigned long
602mktime (unsigned int year, unsigned int mon,
603 unsigned int day, unsigned int hour,
604 unsigned int min, unsigned int sec)
605{
606 if (0 >= (int) (mon -= 2)) { /* 1..12 -> 11,12,1..10 */
607 mon += 12; /* Puts Feb last since it has leap day */
608 year -= 1;
609 }
610
611 return ((((unsigned long)
612 (year/4 - year/100 + year/400 + 367*mon/12 + day) +
613 year*365 - 719499
614 )*24 + hour /* now have hours */
615 )*60 + min /* now have minutes */
616 )*60 + sec; /* finally seconds */
617}
618
619/**
620 * set_normalized_timespec - set timespec sec and nsec parts and normalize
621 *
622 * @ts: pointer to timespec variable to be set
623 * @sec: seconds to set
624 * @nsec: nanoseconds to set
625 *
626 * Set seconds and nanoseconds field of a timespec variable and
627 * normalize to the timespec storage format
628 *
629 * Note: The tv_nsec part is always in the range of
630 * 0 <= tv_nsec < NSEC_PER_SEC
631 * For negative values only the tv_sec field is negative !
632 */
633void set_normalized_timespec (struct timespec *ts, time_t sec, long nsec)
634{
635 while (nsec >= NSEC_PER_SEC) {
636 nsec -= NSEC_PER_SEC;
637 ++sec;
638 }
639 while (nsec < 0) {
640 nsec += NSEC_PER_SEC;
641 --sec;
642 }
643 ts->tv_sec = sec;
644 ts->tv_nsec = nsec;
645}
646
586#if (BITS_PER_LONG < 64) 647#if (BITS_PER_LONG < 64)
587u64 get_jiffies_64(void) 648u64 get_jiffies_64(void)
588{ 649{