Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have chat app. I want allow user message other user only every other week. For example:

  • Week 1 (allowed
  • Week 2 (not allowed)
  • Week 3 (allowed)
  • Week 4 (not allowed) ...

How I can do this? I want write conditional so can say:

if (allowedWeek) {
sendMessage
}

Maybe can use something like this?

DateTime.now().isAfter(X) && DateTime.now().isBefore(Y)

How I can tell DateTime this?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
416 views
Welcome To Ask or Share your Answers For Others

1 Answer

May be you can get week of the year by this package, week_of_year, and decide which week to talk which is not:

import 'package:week_of_year/week_of_year.dart';

void main() {
  final date = DateTime.now();
  print(date.weekOfYear); // Get the iso week of year
  print(date.ordinalDate); // Get the ordinal date
  print(date.isLeapYear); // Is this a leap year?
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...